MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / tmove

Function tmove

lib/lua/src/ltablib.c:115–144  ·  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

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