public static string lua_setupvalue(lua_State L, int funcindex, int n) { lua_lock(L); TValue val = null; CClosure owner = null; UpVal uv = null; TValue fi = imp.index2addr(L, funcindex); imp.api_checknelems(L, 1); string name = imp.aux_upvalue(fi, n, ref val, ref owner, ref uv); if (name != null) { L.top--; imp.setobj(L, val, L.top); if (owner != null) { imp.luaC_barrier(L, owner, L.top); } else if (uv != null) { imp.luaC_upvalbarrier(L, uv); } } lua_unlock(L); return(name); }
public static void lua_upvaluejoin(lua_State L, int fidx1, int n1, int fidx2, int n2) { LClosure f1 = null; UpVal up2 = imp.getupvalref(L, fidx2, n2, ref f1); UpVal up1 = imp.getupvalref(L, fidx1, n1, ref f1); imp.luaC_upvdeccount(L, up1); imp.uvcopy(up1, up2); up1.refcount++; if (imp.upisopen(up1)) { up1.u.open.touched = 1; } imp.luaC_upvalbarrier(L, up1); }
public static string lua_getupvalue(lua_State L, int funcindex, int n) { lua_lock(L); TValue val = null; CClosure cl = null; UpVal uv = null; string name = imp.aux_upvalue(imp.index2addr(L, funcindex), n, ref val, ref cl, ref uv); if (name != null) { imp.setobj2s(L, L.top, val); imp.api_incr_top(L); } lua_unlock(L); return(name); }
public static string aux_upvalue(TValue fi, int n, ref TValue val, ref CClosure owner, ref UpVal uv) { switch (ttype(fi)) { case LUA_TCCL: { /* C closure */ CClosure f = clCvalue(fi); if ((1 <= n && n <= f.nupvalues) == false) { return(null); } val = f.upvalue[n - 1]; if (owner != null) { owner = f; } return(""); } case LUA_TLCL: { /* Lua closure */ LClosure f = clLvalue(fi); Proto p = f.p; if ((1 <= n && n <= p.sizeupvalues) == false) { return(null); } val = f.upvals[n - 1].v; if (uv != null) { uv = f.upvals[n - 1]; } TString name = p.upvalues[n - 1].name; return((name == null) ? "(*no name)" : byte2str(getstr(name))); } default: return(null); /* not a closure */ } }