MCPcopy Create free account
hub / github.com/PlutoLang/Pluto / tremove

Function tremove

src/ltablib.cpp:127–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125}
126
127static int tremove (lua_State *L) {
128 lua_Integer size = aux_getn(L, 1, TAB_RW);
129 lua_Integer pos = luaL_optinteger(L, 2, size);
130 if (pos != size) /* validate 'pos' if given */
131 /* check whether 'pos' is in [1, size + 1] */
132 luaL_argcheck(L, (lua_Unsigned)pos - 1u <= (lua_Unsigned)size, 2,
133 "position out of bounds");
134 lua_geti(L, 1, pos); /* result = t[pos] */
135 for ( ; pos < size; pos++) {
136 lua_geti(L, 1, pos + 1);
137 lua_seti(L, 1, pos); /* t[pos] = t[pos + 1] */
138 }
139 lua_pushnil(L);
140 lua_seti(L, 1, pos); /* remove entry t[pos] */
141 return 1;
142}
143
144
145/*

Callers

nothing calls this directly

Calls 3

lua_getiFunction · 0.85
lua_setiFunction · 0.85
lua_pushnilFunction · 0.85

Tested by

no test coverage detected