MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / tmove

Function tmove

extlibs/lua/src/ltablib.c:114–143  ·  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

112** than origin, or copying to another table.
113*/
114static int tmove (lua_State *L) {
115 lua_Integer f = luaL_checkinteger(L, 2);
116 lua_Integer e = luaL_checkinteger(L, 3);
117 lua_Integer t = luaL_checkinteger(L, 4);
118 int tt = !lua_isnoneornil(L, 5) ? 5 : 1; /* destination table */
119 checktab(L, 1, TAB_R);
120 checktab(L, tt, TAB_W);
121 if (e >= f) { /* otherwise, nothing to move */
122 lua_Integer n, i;
123 luaL_argcheck(L, f > 0 || e < LUA_MAXINTEGER + f, 3,
124 "too many elements to move");
125 n = e - f + 1; /* number of elements to move */
126 luaL_argcheck(L, t <= LUA_MAXINTEGER - n + 1, 4,
127 "destination wrap around");
128 if (t > e || t <= f || (tt != 1 && !lua_compare(L, 1, tt, LUA_OPEQ))) {
129 for (i = 0; i < n; i++) {
130 lua_geti(L, 1, f + i);
131 lua_seti(L, tt, t + i);
132 }
133 }
134 else {
135 for (i = n - 1; i >= 0; i--) {
136 lua_geti(L, 1, f + i);
137 lua_seti(L, tt, t + i);
138 }
139 }
140 }
141 lua_pushvalue(L, tt); /* return destination table */
142 return 1;
143}
144
145
146static 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_pushvalueFunction · 0.85
lua_compareFunction · 0.70
lua_getiFunction · 0.70
lua_setiFunction · 0.70

Tested by

no test coverage detected