| 1896 | |
| 1897 | |
| 1898 | static TValue *index2adr (lua_State *L, int idx) { |
| 1899 | if (idx > 0) { |
| 1900 | TValue *o = L->base + (idx - 1); |
| 1901 | api_check(L, idx <= L->ci->top - L->base); |
| 1902 | if (o >= L->top) return cast(TValue *, luaO_nilobject); |
| 1903 | else return o; |
| 1904 | } |
| 1905 | else if (idx > LUA_REGISTRYINDEX) { |
| 1906 | api_check(L, idx != 0 && -idx <= L->top - L->base); |
| 1907 | return L->top + idx; |
| 1908 | } |
| 1909 | else switch (idx) { /* pseudo-indices */ |
| 1910 | case LUA_REGISTRYINDEX: return registry(L); |
| 1911 | case LUA_ENVIRONINDEX: { |
| 1912 | Closure *func = curr_func(L); |
| 1913 | sethvalue(L, &L->env, func->c.env); |
| 1914 | return &L->env; |
| 1915 | } |
| 1916 | case LUA_GLOBALSINDEX: return gt(L); |
| 1917 | default: { |
| 1918 | Closure *func = curr_func(L); |
| 1919 | idx = LUA_GLOBALSINDEX - idx; |
| 1920 | return (idx <= func->c.nupvalues) |
| 1921 | ? &func->c.upvalue[idx-1] |
| 1922 | : cast(TValue *, luaO_nilobject); |
| 1923 | } |
| 1924 | } |
| 1925 | } |
| 1926 | |
| 1927 | |
| 1928 | static Table *getcurrenv (lua_State *L) { |
no test coverage detected