public LuaState() { mainThread = System.Threading.Thread.CurrentThread.ManagedThreadId; L = LuaDLL.luaL_newstate(); statemap[L] = this; if (main == null) { main = this; } LuaDLLNativeRuntime.Establish(L); refQueue = new Queue <UnrefPair>(); ObjectCache.make(L); LuaDLL.lua_atpanic(L, panicCallback); LuaDLL.luaL_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.lua_dostring(L, PCallCSFunction); PCallCSFunctionRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); pcall(L, init); }
public LuaState() { if (mainThread == 0) { mainThread = System.Threading.Thread.CurrentThread.ManagedThreadId; } L = LuaDLL.luaL_newstate(); statemap[L] = this; LuaDLLNativeRuntime.Establish(L); refQueue = new Queue <UnrefPair>(); ObjectCache.make(L); LuaDLL.lua_atpanic(L, panicCallback); LuaDLL.luaL_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.lua_dostring(L, PCallCSFunction); PCallCSFunctionRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); string newindexfun = @" local getmetatable=getmetatable local rawget=rawget local error=error local type=type local function newindex(ud,k,v) local t=getmetatable(ud) repeat local h=rawget(t,k) if h then if h[2] then h[2](ud,v) return else error('property '..k..' is read only') end end t=rawget(t,'__parent') until t==nil error('can not find '..k) end return newindex "; string indexfun = @" local type=type local error=error local rawget=rawget local getmetatable=getmetatable local function index(ud,k) local t=getmetatable(ud) repeat local fun=rawget(t,k) local tp=type(fun) if tp=='function' then return fun elseif tp=='table' then local f=fun[1] if f then return f(ud) else error('property '..k..' is write only') end end t = rawget(t,'__parent') until t==nil error('Can not find '..k) end return index "; newindex_func = (LuaFunction)doString(newindexfun); index_func = (LuaFunction)doString(indexfun); setupPushVar(); pcall(L, init); createGameObject(); }