示例#1
0
        private static int LuaMetaCachedGC(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);
                }
            }

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

            return(0);
        }
示例#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);
        }