From e52cb7f6fa1dae752c7d30fd8a7240df64985273 Mon Sep 17 00:00:00 2001 From: Louis-Antoine Date: Sun, 8 Nov 2020 17:20:25 +0100 Subject: [PATCH] Throw an error if too many metatables are registered --- src/lua_baselib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 468af0aa1..ac9b6053d 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -250,12 +250,15 @@ static int lib_userdataType(lua_State *L) // Only callable during script loading static int lib_registerMetatable(lua_State *L) { - static UINT32 nextid = 1; + static UINT16 nextid = 1; if (!lua_lumploading) return luaL_error(L, "This function cannot be called from within a hook or coroutine!"); luaL_checktype(L, 1, LUA_TTABLE); + if (nextid == 0) + luaL_error(L, "Too many metatables registered?! Please consider rewriting your script once you are sober again.\n"); + lua_getfield(L, LUA_REGISTRYINDEX, LREG_METATABLES); // 2 // registry.metatables[metatable] = nextid lua_pushvalue(L, 1); // 3