public static bool PushObjFromCache(IntPtr l, object obj) { if (LuaObjCacheSlim.TryPush(l, obj)) { return(true); } var cache = GetObjCache(l); if (cache != null) { IntPtr h; if (cache._Map.TryGetValue(obj, out h)) { l.checkstack(5); PushObjCacheReg(l); // reg if (!l.istable(-1)) { l.pop(1); return(false); } l.pushlightuserdata(h); // reg h l.gettable(-2); // reg ud if (l.isnoneornil(-1)) { l.pop(2); // X return(false); } l.remove(-2); // ud return(true); } } return(false); }
internal static void RegObj(IntPtr l, object obj, int index, IntPtr h) { var pos = l.NormalizeIndex(index); if (obj != null) { LuaObjCacheSlim.Record(obj, l.topointer(pos), pos); } var cache = GetOrCreateObjCache(l); cache._Map[obj] = h; l.checkstack(5); PushOrCreateObjCacheReg(l); // reg l.pushlightuserdata(h); // reg h l.pushvalue(pos); // reg h ud l.settable(-3); // reg l.pop(1); // X }
public static object GetLuaTableObjectDirect(this IntPtr l, int index) { var pos = l.NormalizeIndex(index); object rv; if (LuaObjCacheSlim.TryGet(l, pos, out rv)) { return(rv); } l.checkstack(2); l.pushlightuserdata(LuaConst.LRKEY_TARGET); // #tar l.rawget(pos); // obj if (l.IsUserData(-1)) { rv = l.GetLuaRawObject(-1); } l.pop(1); if (rv != null) { LuaObjCacheSlim.Record(rv, l.topointer(pos), pos); } return(rv); }
private static object GetLuaTableObject(this IntPtr l, int index, out bool isUserData) { var pos = l.NormalizeIndex(index); object rv; if (LuaObjCacheSlim.TryGet(l, pos, out rv)) { isUserData = true; return(rv); } isUserData = false; l.checkstack(2); l.pushlightuserdata(LuaConst.LRKEY_TYPE_TRANS); // #trans l.gettable(pos); // trans ILuaTrans trans = null; if (l.isuserdata(-1)) { trans = l.GetLuaLightObject(-1) as ILuaTrans; } l.pop(1); if (trans != null) { isUserData = true; rv = trans.GetLua(l, index); //// Notice the LuaObjCacheSlim.Record should happen when access #tar from a table //if (rv != null && rv.GetType().IsClass) //{ // LuaObjCacheSlim.Record(rv, l.topointer(pos), pos); //} return(rv); } return(null); }
public void Remove(object obj) { LuaObjCacheSlim.Remove(obj); _Map.Remove(obj); }