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 // We need to keep this in a managed reference so the delegate doesn't get garbage collected panicCallback = new LuaCSFunction(PanicCallback); LuaDLL.lua_atpanic(luaState, panicCallback); // LuaDLL.lua_atlock(luaState, lockCallback = new LuaCSFunction(LockCallback)); // LuaDLL.lua_atunlock(luaState, unlockCallback = new LuaCSFunction(UnlockCallback)); }
public LuaState() { this.L = LuaDLL.luaL_newstate(); LuaDLL.luaL_openlibs(this.L); LuaDLL.lua_pushstring(this.L, "LUAINTERFACE LOADED"); LuaDLL.lua_pushboolean(this.L, true); LuaDLL.lua_settable(this.L, LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_newtable(this.L); LuaDLL.lua_setglobal(this.L, "luanet"); LuaDLL.lua_pushvalue(this.L, LuaIndexes.LUA_GLOBALSINDEX); LuaDLL.lua_getglobal(this.L, "luanet"); LuaDLL.lua_pushstring(this.L, "getmetatable"); LuaDLL.lua_getglobal(this.L, "getmetatable"); LuaDLL.lua_settable(this.L, -3); LuaDLL.lua_pushstring(this.L, "rawget"); LuaDLL.lua_getglobal(this.L, "rawget"); LuaDLL.lua_settable(this.L, -3); LuaDLL.lua_pushstring(this.L, "rawset"); LuaDLL.lua_getglobal(this.L, "rawset"); LuaDLL.lua_settable(this.L, -3); LuaDLL.lua_replace(this.L, LuaIndexes.LUA_GLOBALSINDEX); this.translator = new ObjectTranslator(this, this.L); LuaDLL.lua_replace(this.L, LuaIndexes.LUA_GLOBALSINDEX); this.translator.PushTranslator(this.L); this.panicCallback = new LuaCSFunction(LuaStatic.panic); LuaDLL.lua_atpanic(this.L, this.panicCallback); this.printFunction = new LuaCSFunction(LuaStatic.print); LuaDLL.lua_pushstdcallcfunction(this.L, this.printFunction, 0); LuaDLL.lua_setfield(this.L, LuaIndexes.LUA_GLOBALSINDEX, "print"); this.loadfileFunction = new LuaCSFunction(LuaStatic.loadfile); LuaDLL.lua_pushstdcallcfunction(this.L, this.loadfileFunction, 0); LuaDLL.lua_setfield(this.L, LuaIndexes.LUA_GLOBALSINDEX, "loadfile"); this.dofileFunction = new LuaCSFunction(LuaStatic.dofile); LuaDLL.lua_pushstdcallcfunction(this.L, this.dofileFunction, 0); LuaDLL.lua_setfield(this.L, LuaIndexes.LUA_GLOBALSINDEX, "dofile"); this.import_wrapFunction = new LuaCSFunction(LuaStatic.importWrap); LuaDLL.lua_pushstdcallcfunction(this.L, this.import_wrapFunction, 0); LuaDLL.lua_setfield(this.L, LuaIndexes.LUA_GLOBALSINDEX, "import"); this.loaderFunction = new LuaCSFunction(LuaStatic.loader); LuaDLL.lua_pushstdcallcfunction(this.L, this.loaderFunction, 0); int index = LuaDLL.lua_gettop(this.L); LuaDLL.lua_getfield(this.L, LuaIndexes.LUA_GLOBALSINDEX, "package"); LuaDLL.lua_getfield(this.L, -1, "loaders"); int num = LuaDLL.lua_gettop(this.L); for (int i = LuaDLL.luaL_getn(this.L, num) + 1; i > 1; i--) { LuaDLL.lua_rawgeti(this.L, num, i - 1); LuaDLL.lua_rawseti(this.L, num, i); } LuaDLL.lua_pushvalue(this.L, index); LuaDLL.lua_rawseti(this.L, num, 1); LuaDLL.lua_settop(this.L, 0); this.DoString(LuaStatic.init_luanet); this.tracebackFunction = new LuaCSFunction(LuaStatic.traceback); }
public LuaState() { // Create State L = LuaDLL.luaL_newstate(); // Create LuaInterface library LuaDLL.luaL_openlibs(L); LuaDLL.lua_pushstring(L, "LUAINTERFACE LOADED"); LuaDLL.lua_pushboolean(L, true); LuaDLL.lua_settable(L, (int)LuaIndexes.LUA_REGISTRYINDEX); tracebackFunction = new LuaCSFunction(error_traceback); // We need to keep this in a managed reference so the delegate doesn't get garbage collected panicCallback = new LuaCSFunction(panic); LuaDLL.lua_atpanic(L, panicCallback); printFunction = new LuaCSFunction(print); LuaDLL.lua_pushstdcallcfunction(L, printFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "print"); loadfileFunction = new LuaCSFunction(loadfile); LuaDLL.lua_pushstdcallcfunction(L, loadfileFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "loadfile"); dofileFunction = new LuaCSFunction(dofile); LuaDLL.lua_pushstdcallcfunction(L, dofileFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "dofile"); LuaDLL.lua_pushstdcallcfunction(L, dofileFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "require"); LuaDLL.lua_newtable(L); LuaDLL.lua_newtable(L); LuaDLL.lua_pushstring(L, "v"); LuaDLL.lua_setfield(L, -2, "__mode"); LuaDLL.lua_setmetatable(L, -2); LuaDLL.lua_setfield(L, LuaIndexes.LUA_REGISTRYINDEX, LuaStatic.CACHE_CSHARP_OBJECT_TABLE); // Insert our loader FIRST loaderFunction = new LuaCSFunction(loader); LuaDLL.lua_pushstdcallcfunction(L, loaderFunction); int loaderFunc = LuaDLL.lua_gettop(L); LuaDLL.lua_getfield(L, LuaIndexes.LUA_GLOBALSINDEX, "package"); LuaDLL.lua_getfield(L, -1, "loaders"); int loaderTable = LuaDLL.lua_gettop(L); // Shift table elements right for (int e = LuaDLL.luaL_getn(L, loaderTable) + 1; e > 1; e--) { LuaDLL.lua_rawgeti(L, loaderTable, e - 1); LuaDLL.lua_rawseti(L, loaderTable, e); } LuaDLL.lua_pushvalue(L, loaderFunc); LuaDLL.lua_rawseti(L, loaderTable, 1); LuaDLL.lua_settop(L, 0); }
public LuaState() { _L = LuaDLL.luaL_newstate(); LuaDLL.luaL_openlibs(_L); LuaDLL.lua_atpanic(_L, Panic); LuaDLL.lua_pushcfunction(_L, Print); LuaDLL.lua_setglobal(_L, "print"); InitLuaPath(); Debug.Log("InitLuaState"); }
static public void OpenLibs(IntPtr L) { LuaDLL.lua_atpanic(L, Panic); LuaDLL.lua_pushstdcallcfunction(L, Print); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "print"); LuaDLL.lua_pushstdcallcfunction(L, DoFile); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "dofile"); //#if UNITY_EDITOR //AddLuaLoader(L); //#else AddLuaLoader2(L); //#endif }
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 Lua() { luaState = LuaDLL.luaL_newstate(); translator = new ObjectTranslator(this, luaState); LuaDLL.luaL_openlibs(luaState); 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); LuaDLL.lua_replace(luaState, (int)LuaIndexes.LUA_GLOBALSINDEX); LuaDLL.luaL_dostring(luaState, Lua.init_luanet); panicCallback = new LuaCSFunction(PanicCallback); LuaDLL.lua_atpanic(luaState, panicCallback); }
public LuaState(string LuaNameSpace) { // Create State L = LuaDLL.luaL_newstate(); string errmsg = null; // Create LuaInterface library if (LuaDLL.wluaL_openlibs(L) == LuaDLL.LUA_ERROR) { errmsg = LuaDLL.lua_tostring(L, -1); throw new LuaException(L, errmsg); } if (LuaDLL.wlua_init(L, LuaNameSpace) == LuaDLL.LUA_ERROR) { errmsg = LuaDLL.lua_tostring(L, -1); throw new LuaException(L, errmsg); } panicCallback = new LuaCSFunction(LuaFuncs.panic); LuaDLL.lua_atpanic(L, panicCallback); }
public LuaState() { // Create State L = LuaDLL.luaL_newstate(); // Create LuaInterface library LuaDLL.luaL_openlibs(L); LuaDLL.lua_pushstring(L, "LUAINTERFACE LOADED"); LuaDLL.lua_pushboolean(L, true); LuaDLL.lua_settable(L, (int)LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "luanet"); LuaDLL.lua_pushvalue(L, (int)LuaIndexes.LUA_GLOBALSINDEX); //鍘嬪叆浜哶G琛? LuaDLL.lua_getglobal(L, "luanet"); LuaDLL.lua_pushstring(L, "getmetatable"); LuaDLL.lua_getglobal(L, "getmetatable"); LuaDLL.lua_settable(L, -3); LuaDLL.lua_pushstring(L, "rawget"); LuaDLL.lua_getglobal(L, "rawget"); LuaDLL.lua_settable(L, -3); LuaDLL.lua_pushstring(L, "rawset"); LuaDLL.lua_getglobal(L, "rawset"); LuaDLL.lua_settable(L, -3); // Set luanet as global for object translator LuaDLL.lua_replace(L, (int)LuaIndexes.LUA_GLOBALSINDEX); //鐢╨uanet鏇挎崲_G琛? translator = new ObjectTranslator(this, L); LuaDLL.lua_replace(L, (int)LuaIndexes.LUA_GLOBALSINDEX); //鎭㈠_G琛? translator.PushTranslator(L); // We need to keep this in a managed reference so the delegate doesn't get garbage collected panicCallback = new LuaCSFunction(LuaStatic.panic); LuaDLL.lua_atpanic(L, panicCallback); printFunction = new LuaCSFunction(LuaStatic.print); LuaDLL.lua_pushstdcallcfunction(L, printFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "lprint"); warnFunction = new LuaCSFunction(LuaStatic.warn); LuaDLL.lua_pushstdcallcfunction(L, warnFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "lwarn"); breakFunction = new LuaCSFunction(LuaStatic.breakFunc); LuaDLL.lua_pushstdcallcfunction(L, breakFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "breakpoint"); loadfileFunction = new LuaCSFunction(LuaStatic.loadfile); LuaDLL.lua_pushstdcallcfunction(L, loadfileFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "loadfile"); dofileFunction = new LuaCSFunction(LuaStatic.dofile); LuaDLL.lua_pushstdcallcfunction(L, dofileFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "dofile"); pcallFunction = new LuaCSFunction(LuaStatic.pcall); LuaDLL.lua_pushstdcallcfunction(L, pcallFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "pcall"); LuaDLL.lua_pushstdcallcfunction(L, LuaStatic.errorFunc_traceback); errorFuncRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); // Insert our loader FIRST loaderFunction = new LuaCSFunction(LuaStatic.loader); LuaDLL.lua_pushstdcallcfunction(L, loaderFunction); int loaderFunc = LuaDLL.lua_gettop(L); LuaDLL.lua_getfield(L, LuaIndexes.LUA_GLOBALSINDEX, "package"); LuaDLL.lua_getfield(L, -1, "loaders"); int loaderTable = LuaDLL.lua_gettop(L); // Shift table elements right for (int e = LuaDLL.luaL_getn(L, loaderTable) + 1; e > 1; e--) { LuaDLL.lua_rawgeti(L, loaderTable, e - 1); LuaDLL.lua_rawseti(L, loaderTable, e); } LuaDLL.lua_pushvalue(L, loaderFunc); LuaDLL.lua_rawseti(L, loaderTable, 1); LuaDLL.lua_settop(L, 0); DoString(LuaStatic.init_luanet); tracebackFunction = new LuaCSFunction(LuaStatic.traceback); }
public IntPtr LuaAtPanic(IntPtr panic) { return(LuaDLL.lua_atpanic(L, panic)); }
public LuaState() { // Create State L = LuaDLL.luaL_newstate(); // Create LuaInterface library LuaDLL.luaL_openlibs(L); LuaDLL.lua_pushstring(L, "LUAINTERFACE LOADED"); LuaDLL.lua_pushboolean(L, true); LuaDLL.lua_settable(L, (int)LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "luanet"); LuaDLL.lua_pushvalue(L, (int)LuaIndexes.LUA_GLOBALSINDEX); LuaDLL.lua_getglobal(L, "luanet"); LuaDLL.lua_pushstring(L, "getmetatable"); LuaDLL.lua_getglobal(L, "getmetatable"); LuaDLL.lua_settable(L, -3); // Set luanet as global for object translator LuaDLL.lua_replace(L, (int)LuaIndexes.LUA_GLOBALSINDEX); translator = new ObjectTranslator(this, L); LuaDLL.lua_replace(L, (int)LuaIndexes.LUA_GLOBALSINDEX); GCHandle handle = GCHandle.Alloc(translator, GCHandleType.Pinned); IntPtr thisptr = GCHandle.ToIntPtr(handle); LuaDLL.lua_pushlightuserdata(L, thisptr); LuaDLL.lua_setglobal(L, "_translator"); // We need to keep this in a managed reference so the delegate doesn't get garbage collected panicCallback = new LuaCSFunction(LuaStatic.panic); LuaDLL.lua_atpanic(L, panicCallback); printFunction = new LuaCSFunction(LuaStatic.print); LuaDLL.lua_pushstdcallcfunction(L, printFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "print"); loadfileFunction = new LuaCSFunction(LuaStatic.loadfile); LuaDLL.lua_pushstdcallcfunction(L, loadfileFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "loadfile"); dofileFunction = new LuaCSFunction(LuaStatic.dofile); LuaDLL.lua_pushstdcallcfunction(L, dofileFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "dofile"); // Insert our loader FIRST loaderFunction = new LuaCSFunction(LuaStatic.loader); LuaDLL.lua_pushstdcallcfunction(L, loaderFunction); int loaderFunc = LuaDLL.lua_gettop(L); LuaDLL.lua_getfield(L, LuaIndexes.LUA_GLOBALSINDEX, "package"); LuaDLL.lua_getfield(L, -1, "loaders"); int loaderTable = LuaDLL.lua_gettop(L); // Shift table elements right for (int e = LuaDLL.luaL_getn(L, loaderTable) + 1; e > 1; e--) { LuaDLL.lua_rawgeti(L, loaderTable, e - 1); LuaDLL.lua_rawseti(L, loaderTable, e); } LuaDLL.lua_pushvalue(L, loaderFunc); LuaDLL.lua_rawseti(L, loaderTable, 1); LuaDLL.lua_settop(L, 0); DoString(LuaStatic.init_luanet); tracebackFunction = new LuaCSFunction(LuaStatic.traceback); }
public static IntPtr tolua_atpanic(IntPtr L, LuaCSFunction func) { IntPtr functionPointerForDelegate = Marshal.GetFunctionPointerForDelegate(func); return(LuaDLL.lua_atpanic(L, functionPointerForDelegate)); }