Пример #1
0
        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);
        }
Пример #2
0
        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);
        }