MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / tunpack

Function tunpack

extlibs/lua/src/ltablib.c:193–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191
192
193static int tunpack (lua_State *L) {
194 lua_Unsigned n;
195 lua_Integer i = luaL_optinteger(L, 2, 1);
196 lua_Integer e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1));
197 if (i > e) return 0; /* empty range */
198 n = (lua_Unsigned)e - i; /* number of elements minus 1 (avoid overflows) */
199 if (n >= (unsigned int)INT_MAX || !lua_checkstack(L, (int)(++n)))
200 return luaL_error(L, "too many results to unpack");
201 for (; i < e; i++) { /* push arg[i..e - 1] (to avoid overflows) */
202 lua_geti(L, 1, i);
203 }
204 lua_geti(L, 1, e); /* push last element */
205 return (int)n;
206}
207
208/* }====================================================== */
209

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected