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