From a49a8175e668db69760a3bc0a3c9e7a56351d111 Mon Sep 17 00:00:00 2001 From: ame Date: Mon, 12 Feb 2024 11:35:20 -0600 Subject: copy now works --- src/lua.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'src/lua.c') diff --git a/src/lua.c b/src/lua.c index 33b9309..e7ff11b 100644 --- a/src/lua.c +++ b/src/lua.c @@ -24,7 +24,8 @@ void i_dcopy(lua_State* src, lua_State* dest, void* _seen){ if(seen == NULL) seen = parray_init(); size_t len; int at, at2; - int *sp = malloc(1); + //int *sp = malloc(1); + //int *sp; char* s; void* whar; int old_top = lua_gettop(src); @@ -41,22 +42,43 @@ void i_dcopy(lua_State* src, lua_State* dest, void* _seen){ lua_newtable(dest); at = lua_gettop(dest); at2 = lua_gettop(src); + char aauwu[50] = {0}; + sprintf(aauwu, "%p", lua_topointer(src, at2)); - *sp = at; - whar = parray_get(seen, (void*)lua_topointer(src, at2)); + int* sp = malloc(1); + whar = parray_get(seen, aauwu); if( whar != NULL){ //printf("%s\n",lua_tostring(src, at2 - 1)); - printf("WHAR\n"); - //lua_pop(dest, 1); - //lua_pushvalue(dest, *(int*)whar); + //printf("WHAR\n"); + lua_pop(dest, 1); + lua_rawgeti(dest, LUA_REGISTRYINDEX, *(int*)whar); + + //lua_pushnumber(dest, 23); + /*int abb = lua_gettop(src); + l_pprint(src); + lua_settop(src, abb); + abb = lua_gettop(dest); + printf("\n**\n"); + l_pprint(dest); + lua_settop(dest, abb); + printf("used %i\n",*(int*)whar);*/ return; - } else parray_set(seen, (void*)lua_topointer(src, at2), sp); + } + //lua_pushinteger(dest, 55); + int r = luaL_ref(dest, LUA_REGISTRYINDEX); + lua_rawgeti(dest, LUA_REGISTRYINDEX, r); + *sp = r; + parray_set(seen, aauwu, sp); + //printf("saved %i\n", *sp); + //for(int i = 0; i != seen->len; i++){ + // printf("%i ", *(int*)seen->P[i].value); + //} lua_pushnil(src); for(;lua_next(src, at2) != 0;){ lua_pushvalue(src, -2); int a = lua_gettop(src); - l_pprint(src); + //l_pprint(src); lua_settop(src, a); i_dcopy(src, dest, seen); -- cgit v1.2.3