public static void PushLuaObject(this IntPtr l, object val) { if (l != IntPtr.Zero) { if (val == null) { l.checkstack(6); LuaObjCache.PushOrCreateObjCacheReg(l); // reg l.pushlightuserdata(IntPtr.Zero); // reg 0 l.gettable(-2); // reg ud if (!l.isnoneornil(-1)) { l.remove(-2); // ud return; } l.pop(1); // reg l.getmetatable(-1); // reg meta l.GetField(-1, LuaConst.LS_META_KEY_INDEX); // reg meta index l.pushlightuserdata(IntPtr.Zero); // reg meta index 0 LuaTypeHub.EmptyTypeHub.PushLua(l, null); // reg meta index 0 ud l.pushvalue(-1); // reg meta index 0 ud ud l.insert(-6); // ud reg meta index 0 ud l.settable(-3); // ud reg meta index l.pop(3); // ud } else { if (LuaObjCache.PushObjFromCache(l, val)) { return; } var type = val.GetType(); ILuaTypeHub sub = LuaTypeHub.GetTypeHub(type); if (sub != null) { var h = sub.PushLua(l, val); if (sub.ShouldCache && h != IntPtr.Zero) { LuaObjCache.RegObj(l, val, -1, h); } } else { PushLuaRawObject(l, val); l.PushCommonMetaTable(); l.setmetatable(-2); } } } }
public static void PushLuaExplicit <T>(this IntPtr l, T val) { var type = typeof(T); ILuaTypeHub sub = LuaTypeHub.GetTypeHub(type); if (sub != null) { if (sub.ShouldCache) { if (sub.PushFromCache(l, val)) { return; } } var sub2 = sub as ILuaPush <T>; IntPtr h; if (sub2 != null) { h = sub2.PushLua(l, val); } else { #if ENABLE_PROFILER && ENABLE_PROFILER_LUA_DEEP && !DISABLE_PROFILER_LUA_GC_ALLOC using (var pcon = new Capstones.UnityFramework.ProfilerContext("box val of " + typeof(T).ToString())) #endif h = sub.PushLua(l, val); } if (sub.ShouldCache && h != IntPtr.Zero) { LuaObjCache.RegObj(l, val, -1, h); } } else { PushLuaRawObject(l, val); l.PushCommonMetaTable(); l.setmetatable(-2); } }