I'm having some issues porting some older Lua 5.1 code to Lua 5.2. I would like to be able to use the stock Lua 5.2 dll/lib, so any porting would need to be completed using the existing API for Lua 5.2. To make it a little more complicated, I'm using DllImport
to P/Invoke some of the Lua API calls. This means any of the #define
shortcuts offered will not work. For example using lua_pushglobaltable
wont be possible. Most of the updates are needed because LUA_REGISTRYINDEX
is not longer accessible.
What I have so far is the following:
1a) Replace
lua_pushstring(luaState, "tablename");
lua_settable(luaState, LUA_REGISTRYINDEX); // LUA_REGISTRYINDEX no longer accessible
1b) With
lua_setglobal(luaState, "tablename");
2a) Replace
lua_pushstring(luaState, "tablename");
lua_gettable(luaState, LUA_REGISTRYINDEX); // LUA_REGISTRYINDEX no longer accessible
2b) With
lua_getglobal(luaState, "tablename");
3a) Replace
lua_pushvalue(luaState, LUA_GLOBALSINDEX);
3b) With
// not sure, something equivalent to lua_pushglobaltable(L)
4a) Replace
lua_replace(luaState, LUA_GLOBALSINDEX);
4b) With
// I dont even have a guess here
5a) Replace
luaL_ref(luaState, (int)LuaIndexes.LUA_REGISTRYINDEX); // also luaL_unref
5b) With
luaL_ref(luaState, <some arbitrary constant>); // this is probably wrong
6a) Replace
lua_rawgeti(luaState, LUA_REGISTRYINDEX, reference);
6b) With
lua_rawgeti(luaState, <same arbitrary constant>, reference); // this is probably wrong
7a) Replace
lua_pcall(IntPtr luaState, int nArgs, int nResults, int errfunc);
7b) With
lua_pcallk(IntPtr luaState, int nArgs, int nResults, int errfunc, int ctx, [MarshalAs(UnmanagedType.FunctionPtr)]LuaCSFunction function);
lua_pcallk(luaState, nArgs, nResults, errfunc, 0, null);
8a) Replace
lua_getfield(luaState, LUA_REGISTRYINDEX, meta);
8b) With
luaL_setmetatable(IntPtr luaState, string meta);
9a) Replace
lua_rawset(luaState, LUA_REGISTRYINDEX);
9b) With
lua_settable(luaState, -3);
Right now everything compiles, but I get memory access violation exceptions, which means I probably substituted something incorrectly. Any help would be appreciated.