public static UpVal luaF_findupval (LuaState L, StkId level) { GlobalState g = G(L); GCObjectRef pp = new OpenValRef(L); UpVal p; UpVal uv; while (pp.get() != null && (p = ngcotouv(pp.get())).v >= level) { lua_assert(p.v != p.u.value); if (p.v == level) { /* found a corresponding upvalue? */ if (isdead(g, obj2gco(p))) /* is it dead? */ changewhite(obj2gco(p)); /* ressurect it */ return p; } pp = new NextRef(p); } uv = luaM_new<UpVal>(L); /* not found: create a new one */ uv.tt = LUA_TUPVAL; uv.marked = luaC_white(g); uv.v = level; /* current value lives in the stack */ uv.next = pp.get(); /* chain it in the proper position */ pp.set( obj2gco(uv) ); uv.u.l.prev = g.uvhead; /* double link it in `uvhead' list */ uv.u.l.next = g.uvhead.u.l.next; uv.u.l.next.u.l.prev = uv; g.uvhead.u.l.next = uv; lua_assert(uv.u.l.next.u.l.prev == uv && uv.u.l.prev.u.l.next == uv); return uv; }
public static UpVal luaF_findupval(lua_State L, StkId level) { global_State g = G(L); GCObjectRef pp = new OpenValRef(L); UpVal p; UpVal uv; while (pp.get() != null && (p = gco2uv(pp.get())).v >= level) { lua_assert(p.v != p.u.value); if (p.v == level) /* found a corresponding upvalue? */ { if (isdead(g, obj2gco(p))) /* is it dead? */ { changewhite(obj2gco(p)); /* ressurrect it */ } return(p); } pp = new NextRef(p); } /* not found: create a new one */ uv = luaC_newobj <UpVal>(L, LUA_TUPVAL, (uint)GetUnmanagedSize(typeof(UpVal)), pp, 0).uv; uv.v = level; /* current value lives in the stack */ uv.u.l.prev = g.uvhead; /* double link it in `uvhead' list */ uv.u.l.next = g.uvhead.u.l.next; uv.u.l.next.u.l.prev = uv; g.uvhead.u.l.next = uv; lua_assert(uv.u.l.next.u.l.prev == uv && uv.u.l.prev.u.l.next == uv); return(uv); }
public static UpVal luaF_findupval(lua_State L, StkId level) { global_State g = G(L); GCObjectRef pp = new OpenValRef(L); UpVal p; UpVal uv; while (pp.get() != null && (p = ngcotouv(pp.get())).v >= level) { lua_assert(p.v != p.u.value); if (p.v == level) { /* found a corresponding upvalue? */ if (isdead(g, obj2gco(p))) /* is it dead? */ { changewhite(obj2gco(p)); /* ressurect it */ } return(p); } pp = new NextRef(p); } uv = luaM_new <UpVal>(L); /* not found: create a new one */ uv.tt = LUA_TUPVAL; uv.marked = luaC_white(g); uv.v = level; /* current value lives in the stack */ uv.next = pp.get(); /* chain it in the proper position */ pp.set(obj2gco(uv)); uv.u.l.prev = g.uvhead; /* double link it in `uvhead' list */ uv.u.l.next = g.uvhead.u.l.next; uv.u.l.next.u.l.prev = uv; g.uvhead.u.l.next = uv; lua_assert(uv.u.l.next.u.l.prev == uv && uv.u.l.prev.u.l.next == uv); return(uv); }