Beispiel #1
0
        public static ILuaMeta GetLuaMeta(this IntPtr l, int index)
        {
            l.getfenv(index); // env
            ILuaMeta mex = null;

            if (l.istable(-1))
            {
                l.pushlightuserdata(LuaConst.LRKEY_OBJ_META_EX); // env mkey
                l.gettable(-2);                                  // env mex
                if (l.islightuserdata(-1))
                {
                    mex = l.GetLuaLightObject(-1) as ILuaMeta;
                }
                l.pop(2); // X
            }
            else
            {
                l.pop(1); // X
            }
            return(mex);
        }
Beispiel #2
0
        private static int LuaMetaCommonGC(IntPtr l)
        {
            IntPtr pud  = l.touserdata(1);
            IntPtr hval = System.Runtime.InteropServices.Marshal.ReadIntPtr(pud);

            System.Runtime.InteropServices.GCHandle handle = new System.Runtime.InteropServices.GCHandle();
            object obj = null;

            try
            {
                handle = (System.Runtime.InteropServices.GCHandle)hval;
                obj    = handle.Target;
            }
            catch { }

            if (obj != null)
            {
                var cache = LuaObjCache.GetObjCache(l);
                if (cache != null)
                {
                    cache.Remove(obj);
                }

                ILuaMeta mex = GetLuaMeta(l, 1);
                if (mex != null)
                {
                    mex.gc(l, obj); // note: the gc should not throw any exception!
                }
            }

            try
            {
                handle.Free();
            }
            catch { }

            return(0);
        }