main/lua-luaxml: fix broken LuaXml library on Lua 5.2+
Hello! I've found that the lua5.2-luaxml
and lua5.3-luaxml
are both (sadly) buggy. Minimal repro:
#!/usr/bin/lua5.2
require('LuaXml').eval('<a></a>')
That is expected to return a Lua object representing the parsed XML tree, but instead it raises an error stating: "attempt to index a nil value".
I did some debugging and research and found that this is caused by changes in Lua's internal APIs, whereby registering a C extension doesn't automatically create global variables any more. LuaXml relies on its table of functions being accessible in a global variable called "xml", so it chokes.
One workaround is to require the library as follows:
xml = require('LuaXml')
...since that creates the global variable which LuaXml needs in order to work. But really, the library shouldn't be relying on global variables at all. Anybody can overwrite a global variable at any time.
I have tried to create a patch to fix the problem, but don't have an environment for building APKs yet, so this is untested code