Exemple #1
0
        //FIXME:refer to luaM_new
        //public static object luaM_realloc_<T>(lua_State L)
        //T new_obj = (T)System.Activator.CreateInstance(typeof(T));
        //AddTotalBytes(L, nsize);

        /*
        ** create a new collectable object (with given type and size) and link
        ** it to '*list'. 'offset' tells how many bytes to allocate before the
        ** object itself (used only by states).
        */
        public static GCObject luaC_newobj <T> (lua_State L, int tt, uint sz, GCObjectRef list,
                                                int offset)
        {
            global_State g = G(L);
            GCObject     o = obj2gco(luaM_newobject <T>(L /*, tt, sz*/) /* + offset*/); //FIXME:???no offset

            if (o is TString)                                                           //FIXME:added
            {
                int len_plus_1 = (int)sz - GetUnmanagedSize(typeof(TString));
                ((TString)o).str = new CharPtr(new char[len_plus_1]);
            }
            if (list == null)
            {
                list = new AllGCRef(g);
            } /* standard list for collectable objects */ //FIXME:changed, new PtrRef
            gch(o).marked = luaC_white(g);
            gch(o).tt     = (byte)tt;                     //FIXME:(byte)
            gch(o).next   = list.get();
            list.set(o);
            return(o);
        }
Exemple #2
0
        /*
        ** if object 'o' has a finalizer, remove it from 'allgc' list (must
        ** search the list to find it) and link it in 'finobj' list.
        */
        public static void luaC_checkfinalizer(lua_State L, GCObject o, Table mt)
        {
            global_State g = G(L);

            if (testbit(gch(o).marked, SEPARATED) || /* obj. is already separated... */
                isfinalized(o) ||                    /* ... or is finalized... */
                gfasttm(g, mt, TMS.TM_GC) == null)   /* or has no finalizer? */
            {
                return;                              /* nothing to be done */
            }
            else                                     /* move 'o' to 'finobj' list */
            {
                GCObjectRef p;
                for (p = new AllGCRef(g); p.get() != o; p = new NextRef(gch(p.get())))
                {
                    ;
                }
                p.set(gch(o).next);                     /* remove 'o' from root list */
                gch(o).next = g.finobj;                 /* link it in list 'finobj' */
                g.finobj    = o;
                l_setbit(ref gch(o).marked, SEPARATED); /* mark it as such */
                resetoldbit(o);                         /* see MOVE OLD rule */
            }
        }
Exemple #3
0
        /*
        ** if userdata 'u' has a finalizer, remove it from 'allgc' list (must
        ** search the list to find it) and link it in 'udgc' list.
        */
        public static void luaC_checkfinalizer(lua_State L, Udata u)
        {
            global_State g = G(L);

            if (testbit(u.uv.marked, SEPARATED) ||             /* userdata is already separated... */
                isfinalized(u.uv) ||                           /* ... or is finalized... */
                gfasttm(g, u.uv.metatable, TMS.TM_GC) == null) /* or has no finalization? */
            {
                return;                                        /* nothing to be done */
            }
            else                                               /* move 'u' to 'udgc' list */
            {
                GCObjectRef p;
                for (p = new AllGCRef(g); p.get() != obj2gco(u); p = new NextRef(gch(p.get())))
                {
                    ;
                }
                p.set(u.uv.next);                     /* remove 'u' from root list */
                u.uv.next = g.udgc;                   /* link it in list 'udgc' */
                g.udgc    = obj2gco(u);
                l_setbit(ref u.uv.marked, SEPARATED); /* mark it as such */
                resetoldbit(obj2gco(u));              /* see MOVE OLD rule */
            }
        }