Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion from Lua table to JSON fails because of gluamapper #107

Closed
linkerlin opened this issue Jul 3, 2022 · 8 comments
Closed

Conversion from Lua table to JSON fails because of gluamapper #107

linkerlin opened this issue Jul 3, 2022 · 8 comments
Assignees
Labels
bug This is a bug

Comments

@linkerlin
Copy link

In Algernon's REPL:

lua> json({a=1})
{}

#106

@linkerlin
Copy link
Author

I have read the code , and I find :

		// Convert the Lua table to a map that can be used when converting to JSON (map[string]interface{})
		mapinterface := gluamapper.ToGoValue(table, gluamapper.Option{
			NameFunc: func(s string) string {
				return s
			},
		})

NOTICE that:
to JSON (map[string]interface{})
In the early ,the REPL report:
ERRO[0356] json: unsupported type: map[interface {}]interface {}

@linkerlin
Copy link
Author

image
the map[interface {}]interface {} is from here 👆

@linkerlin
Copy link
Author

linkerlin commented Jul 3, 2022

image
I fixed the bug by changed map[interface{}]interface{} to map[string]interface{}
image

linkerlin added a commit to linkerlin/algernon that referenced this issue Jul 3, 2022
@linkerlin
Copy link
Author

By the way, revert
86c3a7c

@xyproto
Copy link
Owner

xyproto commented Jul 3, 2022

Thanks for reporting, I'm able to reproduce the issue.

@xyproto xyproto self-assigned this Jul 3, 2022
@xyproto xyproto added the bug This is a bug label Jul 3, 2022
@xyproto
Copy link
Owner

xyproto commented Jul 3, 2022

Thanks! Reverting 86c3a7c and applying the patch worked.

However, I already had a fork of gluamapper + gopher-lua that had the suggested changes, so I just switched (back) to those. They were removed some time ago because I mistakenly thought that they were no longer needed.

These two now works again, in main:

json {a=1}
json {a={b=100}}

Thanks for reporting and patching!

@xyproto xyproto closed this as completed Jul 3, 2022
@xyproto xyproto changed the title json() will drop all data in the table which is converting to json Conversion from Lua table to JSON fails because of gluamapper Jul 3, 2022
@tooolbox
Copy link
Collaborator

tooolbox commented Jul 6, 2022

@xyproto I wonder how easy it would be to set up CI/GH Actions to execute Lua scripts with Algernon and check the output, so things like this as well as perhaps #106 and anything similar can be checked and defended against regressions?

@xyproto
Copy link
Owner

xyproto commented Jul 6, 2022

Good suggestion. This should be feasable, either with go test or by fetching the result from Algernon with curl at test time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is a bug
Projects
None yet
Development

No branches or pull requests

3 participants