//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 and link it to '*list' */ 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 RootGCRef(g); /* standard list for collectable objects */ } gch(o).marked = luaC_white(g); gch(o).tt = (byte)tt; //FIXME:(byte) gch(o).next = list.get(); list.set(o); return(o); }
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 2nd part of root list */ { GCObjectRef p; for (p = new RootGCRef(g); p.get() != obj2gco(u); p.set(gch(p.get()).next)) { lua_assert(p.get() != obj2gco(g.mainthread)); /* 'u' must be in this list */ } p.set(u.uv.next); /* remove 'u' from root list */ u.uv.next = g.mainthread.next; /* re-link it in list */ g.mainthread.next = obj2gco(u); l_setbit(ref u.uv.marked, SEPARATED); /* mark it as such */ } }