Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CodeGen/src/NativeState.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct NativeContext

int (*luaH_getn)(Table* t) = nullptr;
Table* (*luaH_new)(lua_State* L, int narray, int lnhash) = nullptr;
Table* (*luaH_clone)(lua_State* L, Table* tt) = nullptr;
Table* (*luaH_clone)(lua_State* L, Table* tt, bool raw) = nullptr;
void (*luaH_resizearray)(lua_State* L, Table* t, int nasize) = nullptr;
TValue* (*luaH_setnum)(lua_State* L, Table* t, int key);

Expand Down
6 changes: 4 additions & 2 deletions VM/src/ltable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,11 +793,10 @@ int luaH_getn(Table* t)
}
}

Table* luaH_clone(lua_State* L, Table* tt)
Table* luaH_clone(lua_State* L, Table* tt, bool raw)
{
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;
Expand All @@ -808,6 +807,9 @@ Table* luaH_clone(lua_State* L, Table* tt)
t->node = cast_to(LuaNode*, dummynode);
t->lastfree = 0;

if (!raw) // Prevent unauthorized assigning of locked metatables
t->metatable = tt->metatable;

if (tt->sizearray)
{
t->array = luaM_newarray(L, tt->sizearray, TValue, t->memcat);
Expand Down
2 changes: 1 addition & 1 deletion VM/src/ltable.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ LUAI_FUNC void luaH_resizehash(lua_State* L, Table* t, int nhsize);
LUAI_FUNC void luaH_free(lua_State* L, Table* t, struct lua_Page* page);
LUAI_FUNC int luaH_next(lua_State* L, Table* t, StkId key);
LUAI_FUNC int luaH_getn(Table* t);
LUAI_FUNC Table* luaH_clone(lua_State* L, Table* tt);
LUAI_FUNC Table* luaH_clone(lua_State* L, Table* tt, bool raw);
LUAI_FUNC void luaH_clear(Table* tt);

#define luaH_setslot(L, t, slot, key) (invalidateTMcache(t), (slot == luaO_nilobject ? luaH_newkey(L, t, key) : cast_to(TValue*, slot)))
Expand Down
5 changes: 1 addition & 4 deletions VM/src/ltablib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,7 @@ static int tisfrozen(lua_State* L)
static int tclone(lua_State* L)
{
luaL_checktype(L, 1, LUA_TTABLE);
luaL_argcheck(L, !luaL_getmetafield(L, 1, "__metatable"), 1, "table has a protected metatable");

Table* tt = luaH_clone(L, hvalue(L->base));

Table* tt = luaH_clone(L, hvalue(L->base), luaL_getmetafield(L, 1, "__metatable") ? true : false);
TValue v;
sethvalue(L, &v, tt);
luaA_pushobject(L, &v);
Expand Down
Loading