From 29f2e1370c30ee347ef14dde7f2fd394d28b2f07 Mon Sep 17 00:00:00 2001 From: Patrick Gundlach Date: Tue, 9 Dec 2025 13:25:05 +0100 Subject: [PATCH] Fix class metatable and example package paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Give class tables a light metatable so userdata-only metamethods don’t run on them. Point example package paths to src/build to run without a global install. This fixes #49 --- src/class_utils.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/class_utils.c b/src/class_utils.c index 750ad4f..cc3a464 100644 --- a/src/class_utils.c +++ b/src/class_utils.c @@ -15,13 +15,17 @@ int register_class(lua_State *L, const char *name, const luaL_Reg *methods, cons } luaL_setfuncs(L, methods, 0); - lua_pop(L, 1); lua_newtable(L); luaL_setfuncs(L, functions, 0); - luaL_getmetatable(L, name); + /* The class table only needs access to the instance metatable for constants; + keep its own metatable light to avoid triggering instance metamethods. */ + lua_newtable(L); + lua_pushvalue(L, -3); + lua_setfield(L, -2, "__index"); lua_setmetatable(L, -2); + + lua_remove(L, -2); return 1; } -