| 191 | |
| 192 | |
| 193 | static int tunpack (lua_State *L) { |
| 194 | lua_Unsigned n; |
| 195 | lua_Integer i = luaL_optinteger(L, 2, 1); |
| 196 | lua_Integer e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1)); |
| 197 | if (i > e) return 0; /* empty range */ |
| 198 | n = (lua_Unsigned)e - i; /* number of elements minus 1 (avoid overflows) */ |
| 199 | if (l_unlikely(n >= (unsigned int)INT_MAX || |
| 200 | !lua_checkstack(L, (int)(++n)))) |
| 201 | return luaL_error(L, "too many results to unpack"); |
| 202 | for (; i < e; i++) { /* push arg[i..e - 1] (to avoid overflows) */ |
| 203 | lua_geti(L, 1, i); |
| 204 | } |
| 205 | lua_geti(L, 1, e); /* push last element */ |
| 206 | return (int)n; |
| 207 | } |
| 208 | |
| 209 | /* }====================================================== */ |
| 210 |
nothing calls this directly
no test coverage detected