From 1155d875d50d6cd79c8aaf9228cd652cbda0cf73 Mon Sep 17 00:00:00 2001
From: Louis-Antoine <lamr@free.fr>
Date: Fri, 30 Oct 2020 15:00:13 +0100
Subject: [PATCH] Use the same names as userdataType() for userdataMetatable()

---
 src/lua_baselib.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/lua_baselib.c b/src/lua_baselib.c
index e60b20095d..468af0aa1e 100644
--- a/src/lua_baselib.c
+++ b/src/lua_baselib.c
@@ -278,8 +278,18 @@ static int lib_registerMetatable(lua_State *L)
 // Returns nil if the string does not refer to a valid userdata type
 static int lib_userdataMetatable(lua_State *L)
 {
+	UINT32 i;
 	const char *udname = luaL_checkstring(L, 1);
-	luaL_getmetatable(L, udname);
+
+	// Find internal metatable name
+	for (i = 0; meta2utype[i].meta; i++)
+		if (!strcmp(udname, meta2utype[i].utype))
+		{
+			luaL_getmetatable(L, meta2utype[i].meta);
+			return 1;
+		}
+
+	lua_pushnil(L);
 	return 1;
 }
 
-- 
GitLab