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