| 133 | |
| 134 | |
| 135 | static int unpack (lua_State *L) { |
| 136 | int i, e; |
| 137 | unsigned int n; |
| 138 | luaL_checktype(L, 1, LUA_TTABLE); |
| 139 | i = luaL_optint(L, 2, 1); |
| 140 | e = luaL_opt(L, luaL_checkint, 3, luaL_len(L, 1)); |
| 141 | if (i > e) return 0; /* empty range */ |
| 142 | n = (unsigned int)e - (unsigned int)i; /* number of elements minus 1 */ |
| 143 | if (n > (INT_MAX - 10) || !lua_checkstack(L, ++n)) |
| 144 | return luaL_error(L, "too many results to unpack"); |
| 145 | lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */ |
| 146 | while (i++ < e) /* push arg[i + 1...e] */ |
| 147 | lua_rawgeti(L, 1, i); |
| 148 | return n; |
| 149 | } |
| 150 | |
| 151 | /* }====================================================== */ |
| 152 |
nothing calls this directly
no test coverage detected