| 125 | } |
| 126 | |
| 127 | static 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 | /* |
nothing calls this directly
no test coverage detected