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

Function tremove

lib/lua/src/ltablib.c:91–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89
90
91static int tremove (lua_State *L) {
92 lua_Integer size = aux_getn(L, 1, TAB_RW);
93 lua_Integer pos = luaL_optinteger(L, 2, size);
94 if (pos != size) /* validate 'pos' if given */
95 /* check whether 'pos' is in [1, size + 1] */
96 luaL_argcheck(L, (lua_Unsigned)pos - 1u <= (lua_Unsigned)size, 2,
97 "position out of bounds");
98 lua_geti(L, 1, pos); /* result = t[pos] */
99 for ( ; pos < size; pos++) {
100 lua_geti(L, 1, pos + 1);
101 lua_seti(L, 1, pos); /* t[pos] = t[pos + 1] */
102 }
103 lua_pushnil(L);
104 lua_seti(L, 1, pos); /* remove entry t[pos] */
105 return 1;
106}
107
108
109/*

Callers

nothing calls this directly

Calls 4

luaL_optintegerFunction · 0.85
lua_getiFunction · 0.85
lua_setiFunction · 0.85
lua_pushnilFunction · 0.85

Tested by

no test coverage detected