// lockCallback, unlockCallback; used by debug code commented out for now public Lua() { luaState = LuaDLL.luaL_newstate(); // steffenj: Lua 5.1.1 API change (lua_open is gone) //LuaDLL.luaopen_base(luaState); // steffenj: luaopen_* no longer used LuaDLL.luaL_openlibs(luaState); // steffenj: Lua 5.1.1 API change (luaopen_base is gone, just open all libs right here) LuaDLL.lua_pushstring(luaState, "LUAINTERFACE LOADED"); LuaDLL.lua_pushboolean(luaState, true); LuaDLL.lua_settable(luaState, (int)LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_newtable(luaState); LuaDLL.lua_setglobal(luaState, "luanet"); LuaDLL.lua_pushvalue(luaState, (int)LuaIndexes.LUA_GLOBALSINDEX); LuaDLL.lua_getglobal(luaState, "luanet"); LuaDLL.lua_pushstring(luaState, "getmetatable"); LuaDLL.lua_getglobal(luaState, "getmetatable"); LuaDLL.lua_settable(luaState, -3); LuaDLL.lua_replace(luaState, (int)LuaIndexes.LUA_GLOBALSINDEX); translator = new ObjectTranslator(this, luaState); LuaDLL.lua_replace(luaState, (int)LuaIndexes.LUA_GLOBALSINDEX); LuaDLL.luaL_dostring(luaState, Lua.init_luanet); // steffenj: lua_dostring renamed to luaL_dostring tracebackFunction = new LuaCSFunction(traceback); // We need to keep this in a managed reference so the delegate doesn't get garbage collected panicCallback = new LuaFunctionCallback(PanicCallback); LuaDLL.lua_atpanic(luaState, panicCallback); }
public Lua(bool enableLengthWorkaround) { // NOTE: You should enable the length workaround on Mac and Linux this.enableLengthWorkaround = enableLengthWorkaround; luaState = LuaDLL.luaL_newstate(); // steffenj: Lua 5.1.1 API change (lua_open is gone) // Load libraries LuaDLL.luaL_openlibs(luaState); // Add LuaInterface marker LuaDLL.lua_pushstring(luaState, "LUAINTERFACE LOADED"); LuaDLL.lua_pushboolean(luaState, true); LuaDLL.lua_settable(luaState, (int)LuaIndexes.LUA_REGISTRYINDEX); translator = new ObjectTranslator(this, luaState); tracebackFunction = new LuaCSFunction(traceback); // We need to keep this in a managed reference so the delegate doesn't get garbage collected panicCallback = new LuaFunctionCallback(PanicCallback); LuaDLL.lua_atpanic(luaState, panicCallback); }
public static extern void lua_atpanic(IntPtr luaState, LuaFunctionCallback panicf);
public Lua() { luaState = LuaDLL.luaL_newstate(); // steffenj: Lua 5.1.1 API change (lua_open is gone) //LuaDLL.luaopen_base(luaState); // steffenj: luaopen_* no longer used LuaDLL.luaL_openlibs(luaState); // steffenj: Lua 5.1.1 API change (luaopen_base is gone, just open all libs right here) LuaDLL.lua_pushstring(luaState, "LUAINTERFACE LOADED"); LuaDLL.lua_pushboolean(luaState, true); LuaDLL.lua_settable(luaState, LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_newtable(luaState); LuaDLL.lua_setglobal(luaState, "luanet"); LuaDLL.lua_pushvalue(luaState, LuaIndexes.LUA_GLOBALSINDEX); LuaDLL.lua_getglobal(luaState, "luanet"); LuaDLL.lua_pushstring(luaState, "getmetatable"); LuaDLL.lua_getglobal(luaState, "getmetatable"); LuaDLL.lua_settable(luaState, -3); LuaDLL.lua_replace(luaState, LuaIndexes.LUA_GLOBALSINDEX); translator=new ObjectTranslator(this,luaState); LuaDLL.lua_replace(luaState, LuaIndexes.LUA_GLOBALSINDEX); LuaDLL.luaL_dostring(luaState, Lua.init_luanet); // steffenj: lua_dostring renamed to luaL_dostring // We need to keep this in a managed reference so the delegate doesn't get garbage collected panicCallback = new LuaFunctionCallback(PanicCallback); LuaDLL.lua_atpanic(luaState, panicCallback); }