MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / tunpack

Function tunpack

lib/lua/src/ltablib.c:194–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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