lua_State *luaE_newthread (lua_State *L) { lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); luaC_link(L, obj2gco(L1), LUA_TTHREAD); preinit_state(L1, G(L)); stack_init(L1, L); /* init stack */ setobj2n(L, gt(L1), gt(L)); /* share table of globals */ L1->hookmask = L->hookmask; L1->basehookcount = L->basehookcount; L1->hook = L->hook; resethookcount(L1); lua_assert(iswhite(obj2gco(L1))); return L1; }
lua_State *luaE_newthread (lua_State *L) { lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); luaC_link(L, obj2gco(L1), LUA_TTHREAD); setthvalue(L, L->top, L1); /* put thread on stack */ incr_top(L); preinit_state(L1, G(L)); stack_init(L1, L); /* init stack */ setobj2n(L, gt(L1), gt(L)); /* share table of globals */ L1->hookmask = L->hookmask; L1->basehookcount = L->basehookcount; L1->hook = L->hook; resethookcount(L1); lua_assert(!isdead(G(L), obj2gco(L1))); L->top--; /* remove thread from stack */ return L1; }
Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e) { Closure *c; luaM_setname(L, "Lua_closure"); c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems))); #if LUA_REFCOUNT c->l.ref = 0; #endif LUA_REFCOUNT luaC_link(L, valtogco(c), LUA_TFUNCTION); c->l.isC = 0; c->l.g = *e; #if LUA_REFCOUNT __AddRef(&c->l.g); #endif LUA_REFCOUNT c->l.nupvalues = cast(lu_byte, nelems); return c; }
void rstack_reject (lua_State *L, GCObject *src) { RStack *rs = rstack(L); RObject *robj = rstack_getrobj(rs, src); lua_assert(robj && src == robj->body); luaC_link(L, src, src->gch.tt); switch(src->gch.tt) { case LUA_TTABLE: luaH_reject(L, gco2h(src)); break; case LUA_TUSERDATA: luaS_rejectu(L, rawgco2u(src)); break; // TODO: implement default: lua_assert(0); } robj->body = NULL; }
lua_State *luaE_newthread (lua_State *L) { lua_State *L1 = mallocstate(L); luaC_link(L, valtogco(L1), LUA_TTHREAD); preinit_state(L1); L1->l_G = L->l_G; #if LUA_REFCOUNT L1->gclist_head.next = (GCObject*)&L->gclist_tail; L1->gclist_head.prev = NULL; L1->gclist_tail.next = NULL; L1->gclist_tail.prev = (GCObject*)&L->gclist_head; L1->gclist_head.tt = LUA_TNIL; L1->gclist_head.marked = 0; L1->gclist_head.ref = 0; L1->gclist_tail.tt = LUA_TNIL; L1->gclist_tail.marked = 0; L1->gclist_tail.ref = 0; L1->ref = 0; #endif LUA_REFCOUNT stack_init(L1, L); /* init stack */ setobj2n(gt(L1), gt(L)); /* share table of globals */ return L1; }
Dispatch::Dispatch( global_State *g ) : GrayObject( g ) { luaC_link( g, this, LUA_TDISPATCH ); }