Esempio n. 1
0
        public LuaState()
        {
            if (mainThread == 0)
            {
                mainThread = System.Threading.Thread.CurrentThread.ManagedThreadId;
            }

            statePointer           = LuaNativeMethods.luaL_newstate();
            statemap[statePointer] = this;

            if (Main == null)
            {
                Main = this;
            }

            refQueue = new Queue <UnrefPair>();
            ObjectCache.Make(statePointer);

            LuaNativeMethods.lua_atpanic(statePointer, PanicCallback);

            LuaNativeMethods.luaL_openlibs(statePointer);

            string callCSFunction = @"
local assert = assert
local function check(ok,...)
    assert(ok, ...)
    return ...
end
return function(cs_func)
    return function(...)
        return check(cs_func(...))
    end
end
";

            LuaNativeMethods.lua_dostring(statePointer, callCSFunction);
            callCSFunctionRef = LuaNativeMethods.luaL_ref(statePointer, LuaIndexes.LUARegistryIndex);
            SetupPushVar();
            ProtectedCall(statePointer, Init);
        }