diff options
author | Mike Pall <mike> | 2017-04-07 12:24:26 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2017-04-07 12:24:26 +0200 |
commit | ef23b70eb64f67c6e6606098baad3cb0ba98d1c3 (patch) | |
tree | 0499f2cd8215e92f260d33d52e333e04d45598ff /src/lj_api.c | |
parent | c67a0982920b94f081a5e2a4e65efc6851e78500 (diff) | |
download | luajit-ef23b70eb64f67c6e6606098baad3cb0ba98d1c3.tar.gz luajit-ef23b70eb64f67c6e6606098baad3cb0ba98d1c3.tar.bz2 luajit-ef23b70eb64f67c6e6606098baad3cb0ba98d1c3.zip |
From Lua 5.2: Add lua_copy().
Contributed by François Perrad.
Diffstat (limited to 'src/lj_api.c')
-rw-r--r-- | src/lj_api.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/lj_api.c b/src/lj_api.c index f0f41766..3c1a07bc 100644 --- a/src/lj_api.c +++ b/src/lj_api.c | |||
@@ -159,30 +159,40 @@ LUA_API void lua_insert(lua_State *L, int idx) | |||
159 | copyTV(L, p, L->top); | 159 | copyTV(L, p, L->top); |
160 | } | 160 | } |
161 | 161 | ||
162 | LUA_API void lua_replace(lua_State *L, int idx) | 162 | static void copy_slot(lua_State *L, TValue *f, int idx) |
163 | { | 163 | { |
164 | api_checknelems(L, 1); | ||
165 | if (idx == LUA_GLOBALSINDEX) { | 164 | if (idx == LUA_GLOBALSINDEX) { |
166 | api_check(L, tvistab(L->top-1)); | 165 | api_check(L, tvistab(f)); |
167 | /* NOBARRIER: A thread (i.e. L) is never black. */ | 166 | /* NOBARRIER: A thread (i.e. L) is never black. */ |
168 | setgcref(L->env, obj2gco(tabV(L->top-1))); | 167 | setgcref(L->env, obj2gco(tabV(f))); |
169 | } else if (idx == LUA_ENVIRONINDEX) { | 168 | } else if (idx == LUA_ENVIRONINDEX) { |
170 | GCfunc *fn = curr_func(L); | 169 | GCfunc *fn = curr_func(L); |
171 | if (fn->c.gct != ~LJ_TFUNC) | 170 | if (fn->c.gct != ~LJ_TFUNC) |
172 | lj_err_msg(L, LJ_ERR_NOENV); | 171 | lj_err_msg(L, LJ_ERR_NOENV); |
173 | api_check(L, tvistab(L->top-1)); | 172 | api_check(L, tvistab(f)); |
174 | setgcref(fn->c.env, obj2gco(tabV(L->top-1))); | 173 | setgcref(fn->c.env, obj2gco(tabV(f))); |
175 | lj_gc_barrier(L, fn, L->top-1); | 174 | lj_gc_barrier(L, fn, f); |
176 | } else { | 175 | } else { |
177 | TValue *o = index2adr(L, idx); | 176 | TValue *o = index2adr(L, idx); |
178 | api_checkvalidindex(L, o); | 177 | api_checkvalidindex(L, o); |
179 | copyTV(L, o, L->top-1); | 178 | copyTV(L, o, f); |
180 | if (idx < LUA_GLOBALSINDEX) /* Need a barrier for upvalues. */ | 179 | if (idx < LUA_GLOBALSINDEX) /* Need a barrier for upvalues. */ |
181 | lj_gc_barrier(L, curr_func(L), L->top-1); | 180 | lj_gc_barrier(L, curr_func(L), f); |
182 | } | 181 | } |
182 | } | ||
183 | |||
184 | LUA_API void lua_replace(lua_State *L, int idx) | ||
185 | { | ||
186 | api_checknelems(L, 1); | ||
187 | copy_slot(L, L->top - 1, idx); | ||
183 | L->top--; | 188 | L->top--; |
184 | } | 189 | } |
185 | 190 | ||
191 | LUA_API void lua_copy(lua_State *L, int fromidx, int toidx) | ||
192 | { | ||
193 | copy_slot(L, index2adr(L, fromidx), toidx); | ||
194 | } | ||
195 | |||
186 | LUA_API void lua_pushvalue(lua_State *L, int idx) | 196 | LUA_API void lua_pushvalue(lua_State *L, int idx) |
187 | { | 197 | { |
188 | copyTV(L, L->top, index2adr(L, idx)); | 198 | copyTV(L, L->top, index2adr(L, idx)); |