** Convert an acceptable index to a pointer to its respective value. ** Non-valid indices return the special nil value 'G(L)->nilvalue'. */
| 58 | ** Non-valid indices return the special nil value 'G(L)->nilvalue'. |
| 59 | */ |
| 60 | static 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 |
no outgoing calls
no test coverage detected