MCPcopy Create free account
hub / github.com/DFHack/dfhack / unpack

Function unpack

depends/lua/src/ltablib.c:207–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205
206
207static 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

Callers

nothing calls this directly

Calls 4

luaL_optintegerFunction · 0.85
lua_checkstackFunction · 0.85
luaL_errorFunction · 0.85
lua_getiFunction · 0.85

Tested by

no test coverage detected