| 89 | |
| 90 | |
| 91 | static 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 | /* |
nothing calls this directly
no test coverage detected