MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / tunpack

Function tunpack

3rd/lua-5.4.3/src/ltablib.c:193–207  ·  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 (l_unlikely(n >= (unsigned int)INT_MAX ||
200 !lua_checkstack(L, (int)(++n))))
201 return luaL_error(L, "too many results to unpack");
202 for (; i < e; i++) { /* push arg[i..e - 1] (to avoid overflows) */
203 lua_geti(L, 1, i);
204 }
205 lua_geti(L, 1, e); /* push last element */
206 return (int)n;
207}
208
209/* }====================================================== */
210

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected