aboutsummaryrefslogtreecommitdiff
path: root/src/lua.c
diff options
context:
space:
mode:
authorame <[email protected]>2026-01-14 00:01:14 -0600
committerame <[email protected]>2026-01-14 00:06:40 -0600
commit9a67405a0983a779fec7328a0767c4d7561c08ea (patch)
treebac59ad1358d7456155cc6b14c4578084fef7ded /src/lua.c
parent8fe66fe2ae75121a6fa6909c04fa5c3cb11cd09c (diff)
fix closures when cloned
Diffstat (limited to 'src/lua.c')
-rw-r--r--src/lua.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/lua.c b/src/lua.c
index a1ae4cd..27547d3 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -257,8 +257,15 @@ void luaI_deepcopy(lua_State* src, lua_State* dest, enum deep_copy_flags flags){
lua_dump(src, writer, (void*)awa, 0);
luaL_loadbuffer(dest, awa->c, awa->len, "fun");
- if(!(flags & SKIP_LOCALS)) lua_assign_upvalues(dest, lua_gettop(dest));
- //lua_remove(dest, -2);
+ //if(!(flags & SKIP_LOCALS)) lua_assign_upvalues(dest, lua_gettop(dest));
+
+ int f = lua_gettop(dest);
+ for(int i = 1; lua_getupvalue(src, -1, i) != NULL; i++){
+ luaI_deepcopy(src, dest, flags);
+ lua_setupvalue(dest, f, i);
+ lua_pop(src, 1);
+ }
+
str_free(awa);
break;
case LUA_TUSERDATA: