aboutsummaryrefslogtreecommitdiff
path: root/ltm.c
diff options
context:
space:
mode:
Diffstat (limited to 'ltm.c')
-rw-r--r--ltm.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/ltm.c b/ltm.c
index 1e7bf829..d4151da4 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 2.15 2013/04/12 19:07:09 roberto Exp roberto $ 2** $Id: ltm.c,v 2.16 2013/04/25 15:59:42 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -18,6 +18,7 @@
18#include "lstring.h" 18#include "lstring.h"
19#include "ltable.h" 19#include "ltable.h"
20#include "ltm.h" 20#include "ltm.h"
21#include "lvm.h"
21 22
22 23
23static const char udatatypename[] = "userdata"; 24static const char udatatypename[] = "userdata";
@@ -104,3 +105,25 @@ int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2,
104 return 1; 105 return 1;
105} 106}
106 107
108
109const TValue *luaT_getequalTM (lua_State *L, Table *mt1, Table *mt2) {
110 const TValue *tm1 = fasttm(L, mt1, TM_EQ);
111 const TValue *tm2;
112 if (tm1 == NULL) return NULL; /* no metamethod */
113 if (mt1 == mt2) return tm1; /* same metatables => same metamethods */
114 tm2 = fasttm(L, mt2, TM_EQ);
115 if (tm2 == NULL) return NULL; /* no metamethod */
116 if (luaV_rawequalobj(tm1, tm2)) /* same metamethods? */
117 return tm1;
118 return NULL;
119}
120
121
122int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2,
123 TMS event) {
124 if (!luaT_callbinTM(L, p1, p2, L->top, event))
125 return -1; /* no metamethod */
126 else
127 return !l_isfalse(L->top);
128}
129