Esempio n. 1
0
        /*
         * CAUTION: LuaInterface.Lua instances can't share the same lua state!
         */
        public Lua(LuaCore.lua_State lState)
        {
            LuaLib.lua_pushstring(lState, "LUAINTERFACE LOADED");
            LuaLib.lua_gettable(lState, (int)LuaIndexes.Registry);

            if (LuaLib.lua_toboolean(lState, -1))
            {
                LuaLib.lua_settop(lState, -2);
                throw new LuaException("There is already a LuaInterface.Lua instance associated with this Lua state");
            }
            else
            {
                LuaLib.lua_settop(lState, -2);
                LuaLib.lua_pushstring(lState, "LUAINTERFACE LOADED");
                LuaLib.lua_pushboolean(lState, true);
                LuaLib.lua_settable(lState, (int)LuaIndexes.Registry);
                luaState = lState;
                LuaLib.lua_pushvalue(lState, (int)LuaIndexes.Globals);
                LuaLib.lua_getglobal(lState, "luanet");
                LuaLib.lua_pushstring(lState, "getmetatable");
                LuaLib.lua_getglobal(lState, "getmetatable");
                LuaLib.lua_settable(lState, -3);
                LuaLib.lua_replace(lState, (int)LuaIndexes.Globals);
                translator = new ObjectTranslator(this, luaState);
                LuaLib.lua_replace(lState, (int)LuaIndexes.Globals);
                LuaLib.luaL_dostring(lState, Lua.init_luanet);                  // steffenj: lua_dostring renamed to luaL_dostring
            }

            _StatePassed = true;
        }
Esempio n. 2
0
 /*
  * Registers the indexing function of CLR objects
  * passed to Lua
  */
 private void createIndexingMetaFunction(LuaCore.lua_State luaState)
 {
     LuaLib.lua_pushstring(luaState, "luaNet_indexfunction");
     LuaLib.luaL_dostring(luaState, MetaFunctions.luaIndexFunction);             // steffenj: lua_dostring renamed to luaL_dostring
     //LuaLib.lua_pushstdcallcfunction(luaState, indexFunction);
     LuaLib.lua_rawset(luaState, (int)LuaIndexes.Registry);
 }
Esempio n. 3
0
        public Lua()
        {
            luaState = LuaLib.luaL_newstate();                  // steffenj: Lua 5.1.1 API change (lua_open is gone)
            //LuaLib.luaopen_base(luaState);	// steffenj: luaopen_* no longer used
            LuaLib.luaL_openlibs(luaState);                     // steffenj: Lua 5.1.1 API change (luaopen_base is gone, just open all libs right here)
            LuaLib.lua_pushstring(luaState, "LUAINTERFACE LOADED");
            LuaLib.lua_pushboolean(luaState, true);
            LuaLib.lua_settable(luaState, (int)LuaIndexes.Registry);
            LuaLib.lua_newtable(luaState);
            LuaLib.lua_setglobal(luaState, "luanet");
            LuaLib.lua_pushvalue(luaState, (int)LuaIndexes.Globals);
            LuaLib.lua_getglobal(luaState, "luanet");
            LuaLib.lua_pushstring(luaState, "getmetatable");
            LuaLib.lua_getglobal(luaState, "getmetatable");
            LuaLib.lua_settable(luaState, -3);
            LuaLib.lua_replace(luaState, (int)LuaIndexes.Globals);
            translator = new ObjectTranslator(this, luaState);
            LuaLib.lua_replace(luaState, (int)LuaIndexes.Globals);
            LuaLib.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 LuaCore.lua_CFunction(PanicCallback);
            LuaLib.lua_atpanic(luaState, panicCallback);

            //LuaLib.lua_atlock(luaState, lockCallback = new LuaCore.lua_CFunction(LockCallback));
            //LuaLib.lua_atunlock(luaState, unlockCallback = new LuaCore.lua_CFunction(UnlockCallback));
        }