pub fn unpack(state: &mut LuaState) -> Result<usize, LuaError>Expand description
Pushes t[i], t[i+1], …, t[j] and returns the count.
static int tunpack (lua_State *L) {
lua_Unsigned n;
lua_Integer i = luaL_optinteger(L, 2, 1);
lua_Integer e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1));
if (i > e) return 0;
n = (lua_Unsigned)e - i;
if (l_unlikely(n >= (unsigned int)INT_MAX ||
!lua_checkstack(L, (int)(++n))))
return luaL_error(L, "too many results to unpack");
for (; i < e; i++) lua_geti(L, 1, i);
lua_geti(L, 1, e);
return (int)n;
}