From 2a3ed541e7e10048bdbfbcc3d693dcc170f87fde Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 1 Jun 2018 15:17:59 -0700 Subject: [PATCH] Added "raw" versions of metamethods, so the original can be easily accessed when overriding a metamethod. --- limmutable.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/limmutable.c b/limmutable.c index 833b526..553c475 100644 --- a/limmutable.c +++ b/limmutable.c @@ -614,10 +614,15 @@ static int Lhash(lua_State *L) static const luaL_Reg Rinstance_metamethods[] = { { "__len", Llen}, + { "__rawlen", Llen}, { "__index", Lindex}, + { "__rawindex", Lindex}, { "__tostring", Ltostring}, + { "__rawtostring", Ltostring}, { "__ipairs", Lipairs}, + { "__rawipairs", Lipairs}, { "__pairs", Lpairs}, + { "__rawpairs", Lpairs}, { "__hash", Lhash}, { "from_table", Lfrom_table}, { "is_instance", Lis_instance}, @@ -629,7 +634,7 @@ static int Lmake_class(lua_State *L) { size_t n_args = lua_gettop(L); // immutable([fields], [methods/metamethods]) - lua_createtable(L, 0, 16); // Rough guess, 16 fields from Rinstance_metamethods + __fields, etc. + lua_createtable(L, 0, 20); // Rough guess, 20 fields from Rinstance_metamethods + __fields, etc. // Stack: [CLS] // Populate CLS.__len, CLS.__index, CLS.__pairs, etc. luaL_register(L,NULL,Rinstance_metamethods);