| 100 | |
| 101 | |
| 102 | static int tremove (lua_State *L) { |
| 103 | lua_Integer size = aux_getn(L, 1, TAB_RW); |
| 104 | lua_Integer pos = luaL_optinteger(L, 2, size); |
| 105 | if (pos != size) /* validate 'pos' if given */ |
| 106 | /* check whether 'pos' is in [1, size + 1] */ |
| 107 | luaL_argcheck(L, (lua_Unsigned)pos - 1u <= (lua_Unsigned)size, 2, |
| 108 | "position out of bounds"); |
| 109 | lua_geti(L, 1, pos); /* result = t[pos] */ |
| 110 | for ( ; pos < size; pos++) { |
| 111 | lua_geti(L, 1, pos + 1); |
| 112 | lua_seti(L, 1, pos); /* t[pos] = t[pos + 1] */ |
| 113 | } |
| 114 | lua_pushnil(L); |
| 115 | lua_seti(L, 1, pos); /* remove entry t[pos] */ |
| 116 | return 1; |
| 117 | } |
| 118 | |
| 119 | |
| 120 | /* |
nothing calls this directly
no test coverage detected