From bb14db9d911e29aa36b6fc5c848d7c209491fe77 Mon Sep 17 00:00:00 2001 From: ccuser44 <68124053+ccuser44@users.noreply.github.com> Date: Thu, 2 Jan 2025 15:25:09 +0200 Subject: [PATCH] Only assign metatable to clone if `__metatable` is undefined --- VM/src/ltable.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/VM/src/ltable.cpp b/VM/src/ltable.cpp index dafb2b3f..635212f6 100644 --- a/VM/src/ltable.cpp +++ b/VM/src/ltable.cpp @@ -797,7 +797,6 @@ Table* luaH_clone(lua_State* L, Table* tt) { Table* t = luaM_newgco(L, Table, sizeof(Table), L->activememcat); luaC_init(L, t, LUA_TTABLE); - t->metatable = tt->metatable; t->tmcache = tt->tmcache; t->array = NULL; t->sizearray = 0; @@ -808,6 +807,9 @@ Table* luaH_clone(lua_State* L, Table* tt) t->node = cast_to(LuaNode*, dummynode); t->lastfree = 0; + if (!luaL_getmetafield(L, 1, "__metatable")) + t->metatable = tt->metatable; + if (tt->sizearray) { t->array = luaM_newarray(L, tt->sizearray, TValue, t->memcat);