| 53 | |
| 54 | |
| 55 | static TValue *index2addr (lua_State *L, int idx) { |
| 56 | CallInfo *ci = L->ci; |
| 57 | if (idx > 0) { |
| 58 | TValue *o = ci->func + idx; |
| 59 | api_check(L, idx <= ci->top - (ci->func + 1), "unacceptable index"); |
| 60 | if (o >= L->top) return NONVALIDVALUE; |
| 61 | else return o; |
| 62 | } |
| 63 | else if (!ispseudo(idx)) { /* negative index */ |
| 64 | api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); |
| 65 | return L->top + idx; |
| 66 | } |
| 67 | else if (idx == LUA_REGISTRYINDEX) |
| 68 | return &G(L)->l_registry; |
| 69 | else { /* upvalues */ |
| 70 | idx = LUA_REGISTRYINDEX - idx; |
| 71 | api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); |
| 72 | if (ttislcf(ci->func)) /* light C function? */ |
| 73 | return NONVALIDVALUE; /* it has no upvalues */ |
| 74 | else { |
| 75 | CClosure *func = clCvalue(ci->func); |
| 76 | return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE; |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | |
| 82 | /* |
no outgoing calls
no test coverage detected