| 117 | |
| 118 | |
| 119 | static int tremove(lua_State *L) { |
| 120 | lua_Integer size = aux_getn(L, 1, TAB_RW); |
| 121 | lua_Integer pos = luaL_optinteger(L, 2, size); |
| 122 | if (pos != size) /* validate 'pos' if given */ |
| 123 | luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, "position out of bounds"); |
| 124 | lua_geti(L, 1, pos); /* result = t[pos] */ |
| 125 | for (; pos < size; pos++) { |
| 126 | lua_geti(L, 1, pos + 1); |
| 127 | lua_seti(L, 1, pos); /* t[pos] = t[pos + 1] */ |
| 128 | } |
| 129 | lua_pushnil(L); |
| 130 | lua_seti(L, 1, pos); /* t[pos] = nil */ |
| 131 | return 1; |
| 132 | } |
| 133 | |
| 134 | |
| 135 | /* |
nothing calls this directly
no test coverage detected