MCPcopy Create free account
hub / github.com/DFHack/dfhack / tmove

Function tmove

depends/lua/src/ltablib.c:128–157  ·  view source on GitHub ↗

** 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. */

Source from the content-addressed store, hash-verified

126** than origin, or copying to another table.
127*/
128static 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
160static void addfield (lua_State *L, luaL_Buffer *b, lua_Integer i) {

Callers

nothing calls this directly

Calls 6

luaL_checkintegerFunction · 0.85
checktabFunction · 0.85
lua_compareFunction · 0.85
lua_getiFunction · 0.85
lua_setiFunction · 0.85
lua_pushvalueFunction · 0.85

Tested by

no test coverage detected