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