** 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.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 |
no outgoing calls
no test coverage detected