aboutsummaryrefslogtreecommitdiff
path: root/ltm.c
diff options
context:
space:
mode:
Diffstat (limited to 'ltm.c')
-rw-r--r--ltm.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/ltm.c b/ltm.c
index 0f0cb91b..1e7bf829 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 2.14 2011/06/02 19:31:40 roberto Exp roberto $ 2** $Id: ltm.c,v 2.15 2013/04/12 19:07:09 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*/
@@ -12,6 +12,7 @@
12 12
13#include "lua.h" 13#include "lua.h"
14 14
15#include "ldo.h"
15#include "lobject.h" 16#include "lobject.h"
16#include "lstate.h" 17#include "lstate.h"
17#include "lstring.h" 18#include "lstring.h"
@@ -75,3 +76,31 @@ const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {
75 return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); 76 return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);
76} 77}
77 78
79
80void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,
81 const TValue *p2, TValue *p3, int hasres) {
82 ptrdiff_t result = savestack(L, p3);
83 setobj2s(L, L->top++, f); /* push function */
84 setobj2s(L, L->top++, p1); /* 1st argument */
85 setobj2s(L, L->top++, p2); /* 2nd argument */
86 if (!hasres) /* no result? 'p3' is third argument */
87 setobj2s(L, L->top++, p3); /* 3rd argument */
88 /* metamethod may yield only when called from Lua code */
89 luaD_call(L, L->top - (4 - hasres), hasres, isLua(L->ci));
90 if (hasres) { /* if has result, move it to its place */
91 p3 = restorestack(L, result);
92 setobjs2s(L, p3, --L->top);
93 }
94}
95
96
97int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2,
98 StkId res, TMS event) {
99 const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */
100 if (ttisnil(tm))
101 tm = luaT_gettmbyobj(L, p2, event); /* try second operand */
102 if (ttisnil(tm)) return 0;
103 luaT_callTM(L, tm, p1, p2, res, 1);
104 return 1;
105}
106