xyproto/algernon

Conversion from Lua table to JSON fails because of gluamapper

linkerlin opened this issue · 8 comments

In Algernon's REPL:

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

#106

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 {}

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

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

By the way, revert
86c3a7c

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

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 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?

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