MCPcopy Create free account
hub / github.com/Cubitect/cubiomes-viewer / index2value

Function index2value

lua/src/lapi.c:60–87  ·  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 + idx;
64 api_check(L, idx <= L->ci->top - (ci->func + 1), "unacceptable index");
65 if (o >= L->top) 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 - (ci->func + 1), "invalid index");
70 return s2v(L->top + idx);
71 }
72 else if (idx == LUA_REGISTRYINDEX)
73 return &G(L)->l_registry;
74 else { /* upvalues */
75 idx = LUA_REGISTRYINDEX - idx;
76 api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large");
77 if (ttisCclosure(s2v(ci->func))) { /* C closure? */
78 CClosure *func = clCvalue(s2v(ci->func));
79 return (idx <= func->nupvalues) ? &func->upvalue[idx-1]
80 : &G(L)->nilvalue;
81 }
82 else { /* light C function or Lua function (through a hook)?) */
83 api_check(L, ttislcf(s2v(ci->func)), "caller not a C function");
84 return &G(L)->nilvalue; /* no upvalues */
85 }
86 }
87}
88
89
90

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