** Copy elements (1[f], ..., 1[e]) into (tt[t], tt[t+1], ...). Whenever ** possible, copy in increasing order, which is better for rehashing. ** "possible" means destination after original range, or smaller ** than origin, or copying to another table. */
| 126 | ** than origin, or copying to another table. |
| 127 | */ |
| 128 | static int tmove (lua_State *L) { |
| 129 | lua_Integer f = luaL_checkinteger(L, 2); |
| 130 | lua_Integer e = luaL_checkinteger(L, 3); |
| 131 | lua_Integer t = luaL_checkinteger(L, 4); |
| 132 | int tt = !lua_isnoneornil(L, 5) ? 5 : 1; /* destination table */ |
| 133 | checktab(L, 1, TAB_R); |
| 134 | checktab(L, tt, TAB_W); |
| 135 | if (e >= f) { /* otherwise, nothing to move */ |
| 136 | lua_Integer n, i; |
| 137 | luaL_argcheck(L, f > 0 || e < LUA_MAXINTEGER + f, 3, |
| 138 | "too many elements to move"); |
| 139 | n = e - f + 1; /* number of elements to move */ |
| 140 | luaL_argcheck(L, t <= LUA_MAXINTEGER - n + 1, 4, |
| 141 | "destination wrap around"); |
| 142 | if (t > e || t <= f || (tt != 1 && !lua_compare(L, 1, tt, LUA_OPEQ))) { |
| 143 | for (i = 0; i < n; i++) { |
| 144 | lua_geti(L, 1, f + i); |
| 145 | lua_seti(L, tt, t + i); |
| 146 | } |
| 147 | } |
| 148 | else { |
| 149 | for (i = n - 1; i >= 0; i--) { |
| 150 | lua_geti(L, 1, f + i); |
| 151 | lua_seti(L, tt, t + i); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | lua_pushvalue(L, tt); /* return destination table */ |
| 156 | return 1; |
| 157 | } |
| 158 | |
| 159 | |
| 160 | static void addfield (lua_State *L, luaL_Buffer *b, lua_Integer i) { |
nothing calls this directly
no test coverage detected