| 203 | |
| 204 | |
| 205 | static int tunpack (lua_State *L) { |
| 206 | lua_Unsigned n; |
| 207 | lua_Integer i = luaL_optinteger(L, 2, 1); |
| 208 | lua_Integer e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1)); |
| 209 | if (i > e) return 0; /* empty range */ |
| 210 | n = l_castS2U(e) - l_castS2U(i); /* number of elements minus 1 */ |
| 211 | if (l_unlikely(n >= (unsigned int)INT_MAX || |
| 212 | !lua_checkstack(L, (int)(++n)))) |
| 213 | return luaL_error(L, "too many results to unpack"); |
| 214 | for (; i < e; i++) { /* push arg[i..e - 1] (to avoid overflows) */ |
| 215 | lua_geti(L, 1, i); |
| 216 | } |
| 217 | lua_geti(L, 1, e); /* push last element */ |
| 218 | return (int)n; |
| 219 | } |
| 220 | |
| 221 | /* }====================================================== */ |
| 222 |
nothing calls this directly
no test coverage detected