Open nuive opened 1 year ago
Bumping this up because I'm super interested in the problem as well as the script op is building that greatly improves accessibility for a game series I play a lot, and the issue seems to have been berried.
I've edited first comment. For some reason, part of the code became broken.
By the way, now I'm almost sure the error is related to how Lua 5.1 handles environments, metatables and all of that. I think that in some momment the engine creates some table which is OK for Lua 5.2+ structure, but not for Lua 5.1, and Lua 5.1 finds a table when its looking for a function. The problem is I cannot find where I can start in order to fix that.
I'm finding some issues trying to use mGBA with Lua 5.1.
What I've found and what I've fixed:
script/engines/lua.c: line 224:
Original code:
script/engines/lua.c: ...
My solution: As lua_getupvalue is getting the _ENV upvalue which lua_load creates when loading a script on Lua 5.2+, for Lua 5.1 I replaced those two lua_getupvalue calls with getfenv calls, which get the _G variable of the loaded script, which should be equivalent to the _ENV variable from Lua 5.2+:
This fixed the crash, but now I'm finding another error when loading any script: [ERROR] attempt to call a table value.
I think this is related to environments too (something with Lua 5.1 creating an environment for each function it declares or something like that, but I'm a bit lost here.
Any idea?