public static void RefString(IntPtr strPoint, int index, string s, IntPtr L) { int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_pushvalue(L, index); //把字符串ref了之后就不GC了 LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_settop(L, oldTop); stringDict[(long)strPoint] = s; }
static LuaDelegate newDelegate(IntPtr l, int p) { LuaState state = LuaState.get(l); LuaDLL.lua_pushvalue(l, p); // push function int fref = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX); // new ref function LuaDelegate f = new LuaDelegate(l, fref); LuaDLL.lua_pushvalue(l, p); LuaDLL.lua_pushinteger(l, fref); LuaDLL.lua_settable(l, -3); // __LuaDelegate[func]= fref state.delgateMap[fref] = f; return(f); }
// Token: 0x060001B5 RID: 437 RVA: 0x0000930C File Offset: 0x0000750C public LuaThreadWrapper(LuaFunction func) { UnityEngine.Debug.LogFormat("LuaThreadWrapper.ctor/1: {0}", new object[] { LuaDLL.lua_gettop(func.L) }); this.state = LuaState.get(func.L); this._thread = LuaDLL.lua_newthread(func.L); this.valueref = LuaDLL.luaL_ref(func.L, LuaIndexes.LUA_REGISTRYINDEX); func.push(func.L); LuaDLL.lua_xmove(func.L, this._thread, 1); UnityEngine.Debug.LogFormat("LuaThreadWrapper.ctor/2: {0}", new object[] { LuaDLL.lua_gettop(func.L) }); }
public LuaState() { mainThread = Thread.CurrentThread.ManagedThreadId; L = LuaDLL.luaL_newstate(); statemap[L] = this; if (main == null) { main = this; } 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 * ";*/ string PCallCSFunction = @" return function(cs_func) return function(...) return cs_func(...) end end "; LuaDLL.lua_dostring(L, PCallCSFunction); PCallCSFunctionRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); pcall(L, init); }
static internal object checkVar(IntPtr l, int p) { LuaTypes type = LuaDLL.lua_type(l, p); switch (type) { case LuaTypes.LUA_TNUMBER: { return(LuaDLL.lua_tonumber(l, p)); } case LuaTypes.LUA_TSTRING: { return(LuaDLL.lua_tostring(l, p)); } case LuaTypes.LUA_TBOOLEAN: { return(LuaDLL.lua_toboolean(l, p)); } case LuaTypes.LUA_TFUNCTION: { LuaDLL.lua_pushvalue(l, p); int r = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX); LuaFunction v = new LuaFunction(l, r); return(v); } case LuaTypes.LUA_TTABLE: { LuaDLL.lua_pushvalue(l, p); int r = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX); LuaTable v = new LuaTable(l, r); return(v); } case LuaTypes.LUA_TUSERDATA: return(LuaObject.checkObj(l, p)); default: return(null); } }
public LuaState() { if (mainThread == 0) { mainThread = System.Threading.Thread.CurrentThread.ManagedThreadId; } L = LuaDLL.luaL_newstate(); statemap[L] = this; if (main == null) { main = this; } 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); setupPushVar(); pcall(L, init); }
public static int pushTry(IntPtr l) { if (!LuaState.get(l).isMainThread()) { Logger.LogError("Can't call lua function in bg thread"); return(0); } if (errorRef == 0) { LuaDLL.lua_pushcfunction(l, LuaState.errorFunc); LuaDLL.lua_pushvalue(l, -1); errorRef = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX); } else { LuaDLL.lua_getref(l, errorRef); } return(LuaDLL.lua_gettop(l)); }
public LuaState() { mainThread = System.Threading.Thread.CurrentThread.ManagedThreadId; L = LuaDLL.luaL_newstate(); statemap[L] = this; if (main == null) { main = this; } refQueue = new Queue <UnrefPair>(); ObjectCache.make(L); //lua作爲host的時候設置錯誤處理函數 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 "; //wrap the cs_func in a new function, which check it's result whether is OK //call PCallCSFunction will return the wraped function LuaDLL.lua_dostring(L, PCallCSFunction); PCallCSFunctionRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); setupPushVar(); pcall(L, init); }
static LuaDelegate newDelegate(IntPtr l, int p) { LuaState state = LuaState.get(l); LuaDLL.lua_pushvalue(l, p); // push function IntPtr ptr = LuaDLL.lua_topointer(l, -1); int fref = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX); // new ref function LuaDelegate f = new LuaDelegate(l, fref); LuaDLL.lua_pushvalue(l, p); LuaDLL.lua_pushinteger(l, fref); LuaDLL.lua_settable(l, -3); // __LuaDelegate[func]= fref state.delegateMap[fref] = f; string s1 = string.Empty, s2 = string.Empty; if (SLuaSetting.Instance.RecordObjectStackTrace) { s1 = Environment.StackTrace; s2 = Logger.GetLuaStackTrack(l, "newdelegate"); } state.delegateStackTraces[fref] = new string[] { ptr.ToInt64().ToString("x8"), s1, s2 }; return(f); }
public LuaState() { if (mainThread == 0) { mainThread = System.Threading.Thread.CurrentThread.ManagedThreadId; } L = LuaDLL.luaL_newstate(); statemap[L] = this; 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(); }
public LuaTable(LuaState state) : base(state, 0) { LuaDLL.lua_newtable(L); valueref = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); }
public static void init(IntPtr l) { 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 h[2](ud,v) return 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 sub=string.sub 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 return fun[1](ud) end t = rawget(t,'__parent') until t==nil error('Can not find '..k) end return index "; if (LuaDLL.luaL_dostring(l, newindexfun) != 0) { throwLuaError(l); return; } newindex_ref = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX); if (LuaDLL.luaL_dostring(l, indexfun) != 0) { throwLuaError(l); return; } index_ref = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX); LuaVarObject.init(l); //LuaValueType.init(l); }
public static void init(IntPtr l) { 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 sub=string.sub 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 if fun[1] then return fun[1](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 "; if (LuaDLL.luaL_dostring(l, newindexfun) != 0) { throwLuaError(l); return; } newindex_ref = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX); if (LuaDLL.luaL_dostring(l, indexfun) != 0) { throwLuaError(l); return; } index_ref = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX); // object method LuaDLL.lua_newtable(l); addMember(l, ToString); addMember(l, GetHashCode); addMember(l, Equals); LuaDLL.lua_setfield(l, LuaIndexes.LUA_REGISTRYINDEX, "__luabaseobject"); LuaVarObject.init(l); LuaDLL.lua_newtable(l); LuaDLL.lua_setglobal(l, DelgateTable); setupPushVar(); }
static public object checkVar(IntPtr l, int p) { LuaTypes type = LuaDLL.lua_type(l, p); switch (type) { case LuaTypes.LUA_TNUMBER: { return(LuaDLL.lua_tonumber(l, p)); } case LuaTypes.LUA_TSTRING: { return(LuaDLL.lua_tostring(l, p)); } case LuaTypes.LUA_TBOOLEAN: { return(LuaDLL.lua_toboolean(l, p)); } case LuaTypes.LUA_TFUNCTION: { LuaDLL.lua_pushvalue(l, p); int r = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX); LuaFunction v = new LuaFunction(l, r); return(v); } case LuaTypes.LUA_TTABLE: { if (isLuaValueType(l, p)) { if (luaTypeCheck(l, p, "Vector2")) { Vector2 v; checkType(l, p, out v); return(v); } else if (luaTypeCheck(l, p, "Vector3")) { Vector3 v; checkType(l, p, out v); return(v); } else if (luaTypeCheck(l, p, "Vector4")) { Vector4 v; checkType(l, p, out v); return(v); } else if (luaTypeCheck(l, p, "Quaternion")) { Quaternion v; checkType(l, p, out v); return(v); } else if (luaTypeCheck(l, p, "Color")) { Color c; checkType(l, p, out c); return(c); } LuaDLL.luaL_error(l, "unknown lua value type"); return(null); } else if (isLuaClass(l, p)) { return(checkObj(l, p)); } else { LuaDLL.lua_pushvalue(l, p); int r = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX); LuaTable v = new LuaTable(l, r); return(v); } } case LuaTypes.LUA_TUSERDATA: return(LuaObject.checkObj(l, p)); default: return(null); } }
public void Renew() { Dispose(true); LuaDLL.lua_newtable(L); valueref = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); }