예제 #1
0
    void Start()
    {
        Lua.lua_State L = Lua.lua_open();
        if (luaL_dostring(L, "return 42, 'butts'"))
        {
            Debug.Log("Success");

            Debug.Log(Lua.lua_tonumber(L, -2));
            Debug.Log(Lua.lua_tostring(L, -1));
        }
        else
        {
            Debug.Log("Failure");
        }
        Lua.lua_close(L);
    }
예제 #2
0
파일: Lua.cs 프로젝트: rumkex/LuaInterface
        /*
            * 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;
        }
예제 #3
0
파일: Lua.cs 프로젝트: rumkex/LuaInterface
        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));
        }
예제 #4
0
 static bool luaL_dostring(Lua.lua_State L, Lua.CharPtr s)
 {
     return(!(Lua.luaL_loadstring(L, s) == 1 || Lua.lua_pcall(L, 0, Lua.LUA_MULTRET, 0) == 1));
 }