MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / index2value

Function index2value

third-party/lua-5.5.0/src/lapi.c:58–86  ·  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

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

Callers 15

lua_copyFunction · 0.70
lua_pushvalueFunction · 0.70
lua_typeFunction · 0.70
lua_iscfunctionFunction · 0.70
lua_isintegerFunction · 0.70
lua_isnumberFunction · 0.70
lua_isstringFunction · 0.70
lua_isuserdataFunction · 0.70
lua_rawequalFunction · 0.70
lua_compareFunction · 0.70
(lua_numbertocstring)Function · 0.70
lua_tonumberxFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected