MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / unpack

Function unpack

third-party/lua-5.2.4/src/ltablib.c:137–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

luaL_lenFunction · 0.85
luaL_checktypeFunction · 0.70
lua_checkstackFunction · 0.70
luaL_errorFunction · 0.70
lua_rawgetiFunction · 0.70

Tested by

no test coverage detected