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