MCPcopy Create free account
hub / github.com/Overload-Technologies/Overload / index2value

Function index2value

Dependencies/lua/src/lapi.c:60–88  ·  view source on GitHub ↗

** Convert an acceptable index to a pointer to its respective value. ** Non-valid indices return the special nil value 'G(L)->nilvalue'. */

Source from the content-addressed store, hash-verified

58** Non-valid indices return the special nil value 'G(L)->nilvalue'.
59*/
60static TValue *index2value (lua_State *L, int idx) {
61 CallInfo *ci = L->ci;
62 if (idx > 0) {
63 StkId o = ci->func.p + idx;
64 api_check(L, idx <= ci->top.p - (ci->func.p + 1), "unacceptable index");
65 if (o >= L->top.p) return &G(L)->nilvalue;
66 else return s2v(o);
67 }
68 else if (!ispseudo(idx)) { /* negative index */
69 api_check(L, idx != 0 && -idx <= L->top.p - (ci->func.p + 1),
70 "invalid index");
71 return s2v(L->top.p + idx);
72 }
73 else if (idx == LUA_REGISTRYINDEX)
74 return &G(L)->l_registry;
75 else { /* upvalues */
76 idx = LUA_REGISTRYINDEX - idx;
77 api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large");
78 if (ttisCclosure(s2v(ci->func.p))) { /* C closure? */
79 CClosure *func = clCvalue(s2v(ci->func.p));
80 return (idx <= func->nupvalues) ? &func->upvalue[idx-1]
81 : &G(L)->nilvalue;
82 }
83 else { /* light C function or Lua function (through a hook)?) */
84 api_check(L, ttislcf(s2v(ci->func.p)), "caller not a C function");
85 return &G(L)->nilvalue; /* no upvalues */
86 }
87 }
88}
89
90
91

Callers 15

lua_copyFunction · 0.85
lua_pushvalueFunction · 0.85
lua_typeFunction · 0.85
lua_iscfunctionFunction · 0.85
lua_isintegerFunction · 0.85
lua_isnumberFunction · 0.85
lua_isstringFunction · 0.85
lua_isuserdataFunction · 0.85
lua_rawequalFunction · 0.85
lua_compareFunction · 0.85
lua_tonumberxFunction · 0.85
lua_tointegerxFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected