public static CharPtr lua_setupvalue(lua_State L, int funcindex, int n) { CharPtr name; TValue val = null; /* to avoid warnings */ CClosure owner = null; UpVal uv = null; StkId fi; lua_lock(L); fi = index2addr(L, funcindex); api_checknelems(L, 1); name = aux_upvalue(fi, n, ref val, ref owner, ref uv); if (name != null) { StkId.dec(ref L.top); setobj(L, val, L.top); if (owner != null) { luaC_barrier(L, owner, L.top); } else if (uv != null) { luaC_upvalbarrier(L, uv); } } lua_unlock(L); return(name); }
static CharPtr aux_upvalue(StkId fi, int n, ref TValue val, ref GCObject owner) { switch (ttype(fi)) { case LUA_TCCL: { /* C closure */ CClosure f = clCvalue(fi); if (!(1 <= n && n <= f.nupvalues)) { return(null); } val = f.upvalue[n - 1]; /*if (owner)*/ owner = obj2gco(f); //FIXME: changed return(""); } case LUA_TLCL: { /* Lua closure */ LClosure f = clLvalue(fi); TString name; Proto p = f.p; if (!(1 <= n && n <= p.sizeupvalues)) { return(null); } val = f.upvals[n - 1].v; /*if (owner)*/ owner = obj2gco(f.upvals[n - 1]); //FIXME: changed name = p.upvalues[n - 1].name; return((name == null) ? "" : getstr(name)); /* no debug information? */ } default: return(null); /* not a closure */ } }
public static void setclCvalue(lua_State L, TValue obj, CClosure x) { TValue io = obj; CClosure x_ = (CClosure)x; io.value_.gc = obj2gco((ClosureHeader)x_); settt_(io, ctb(LUA_TCCL)); //FIXME:chagned, val_(io) checkliveness(G(L), io); }
public static CClosure luaF_newCclosure(lua_State L, int n) { CClosure c = luaC_newobj <CClosure> (L, LUA_TCCL); c.nupvalues = (byte)n; return(c); }
public static CClosure luaF_newCclosure(lua_State L, int n) { GCObject o = luaC_newobj <Closure>(L, LUA_TCCL, sizeCclosure(n)); CClosure c = gco2ccl(o); c.nupvalues = cast_byte(n); c.upvalue = new TValue[n]; //FIXME:added??? for (int i = 0; i < n; i++) //FIXME:added??? { c.upvalue[i] = new lua_TValue(); //FIXME:??? //FIXME:added??? } return(c); }
public static CharPtr lua_getupvalue(lua_State L, int funcindex, int n) { CharPtr name; TValue val = null; /* to avoid warnings */ lua_lock(L); CClosure null_ = null; //FIXME:added UpVal null__ = new UpVal(); //FIXME:added name = aux_upvalue(index2addr(L, funcindex), n, ref val, ref null_, ref null__); //FIXME:changed if (name != null) { setobj2s(L, L.top, val); api_incr_top(L); } lua_unlock(L); return(name); }
static TValue index2addr(lua_State L, int idx) { CallInfo ci = L.ci; if (idx > 0) { TValue o = ci.func + idx; api_check(L, idx <= ci.top - (ci.func + 1), "unacceptable index"); if (o >= L.top) { return(luaO_nilobject); } else { return(o); } } else if (idx > LUA_REGISTRYINDEX) { api_check(L, idx != 0 && -idx <= L.top - (ci.func + 1), "invalid index"); return(L.top + idx); } else if (idx == LUA_REGISTRYINDEX) { return(G(L).l_registry); } else /* upvalues */ { idx = LUA_REGISTRYINDEX - idx; api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); if (ttislcf(ci.func)) /* light C function? */ { return((TValue)(luaO_nilobject)); /* it has no upvalues */ } else { CClosure func = clCvalue(ci.func); return((idx <= func.nupvalues) ? func.upvalue[idx - 1] : (TValue)(luaO_nilobject)); } } }
private static object lua_upvalueid(lua_State L, int fidx, int n) { StkId fi = index2addr(L, fidx); switch (ttype(fi)) { case LUA_TLCL: { /* lua closure */ LClosure null_ = null; //FIXME:added return(getupvalref(L, fidx, n, ref null_).get()); } case LUA_TCCL: { /* C closure */ CClosure f = clCvalue(fi); api_check(L, 1 <= n && n <= f.nupvalues, "invalid upvalue index"); return(f.upvalue[n - 1]); } default: { api_check(L, 0, "closure expected"); return(null); } } }
public Closure() { c = new CClosure(this); l = new LClosure(this); }
public static void setclCvalue(lua_State L, int o, CClosure t) { setclCvalue(L, L.stack[o], t); }
public static void setclCvalue(lua_State L, TValue obj, CClosure x) { obj.value_.o = x; settt_(obj, ctb(LUA_TCCL)); checkliveness(G(L), obj); }
public Closure() { c = luaM_newobject <CClosure> (null); l = luaM_newobject <LClosure> (null); }