From ae034cf6921a0e413e0abbf41ac1c50c4dff38ed Mon Sep 17 00:00:00 2001 From: Bruce Date: Wed, 24 Dec 2025 19:27:20 +0800 Subject: [PATCH] fix: use same hash seed when creating VM for shared tables (#2122) When creating a new Lua VM to load shared tables, use the same hash seed from the parent VM instead of generating a new random seed. Different VMs have different hash seeds, causing identical strings to have different hash values. When looking up string keys in a shared table from another VM, the hash-based bucket lookup fails because the search key's hash doesn't match the stored key's hash. Solution: Pass G(L)->seed to lua_newstate() instead of using luaL_newstate() which generates a new random seed each time. --- lualib-src/lua-sharetable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lualib-src/lua-sharetable.c b/lualib-src/lua-sharetable.c index 8a84e7bf..6588053a 100644 --- a/lualib-src/lua-sharetable.c +++ b/lualib-src/lua-sharetable.c @@ -192,7 +192,7 @@ load_matrixfile(lua_State *L) { static int matrix_from_file(lua_State *L) { - lua_State *mL = luaL_newstate(); + lua_State *mL = lua_newstate(luaL_alloc, NULL, G(L)->seed); if (mL == NULL) { return luaL_error(L, "luaL_newstate failed"); }