public LuaState() { mainThread = System.Threading.Thread.CurrentThread.ManagedThreadId; L = LuaDLL.puaL_newstate(); statemap[L] = this; if (main == null) { main = this; } refQueue = new Queue <UnrefPair>(); ObjectCache.make(L); LuaDLL.pua_atpanic(L, panicCallback); LuaDLL.puaL_openlibs(L); string PCallCSFunction = @" local assert = assert local function check(ok,...) assert(ok, ...) return ... end return function(cs_func) return function(...) return check(cs_func(...)) end end "; LuaDLL.pua_dostring(L, PCallCSFunction); PCallCSFunctionRef = LuaDLL.puaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); pcall(L, init); }
public LuaState() { this.mainThread = Thread.CurrentThread.ManagedThreadId; this.L = LuaDLL.puaL_newstate(); LuaState.statemap[this.L] = this; if (LuaState.main == null) { LuaState.main = this; } this.refQueue = new Queue <LuaState.UnrefPair>(); ObjectCache.make(this.L); LuaDLL.pua_atpanic(this.L, new LuaCSFunction(LuaState.panicCallback)); LuaDLL.puaL_openlibs(this.L); string chunk = "\r\nlocal assert = assert\r\nlocal function check(ok,...)\r\n\tassert(ok, ...)\r\n\treturn ...\r\nend\r\nreturn function(cs_func)\r\n\treturn function(...)\r\n\t\treturn check(cs_func(...))\r\n\tend\r\nend\r\n"; LuaDLL.pua_dostring(this.L, chunk); this.PCallCSFunctionRef = LuaDLL.puaL_ref(this.L, LuaIndexes.LUA_REGISTRYINDEX); LuaState.pcall(this.L, new LuaCSFunction(LuaState.init)); }