aboutsummaryrefslogtreecommitdiff
path: root/ltm.c
diff options
context:
space:
mode:
Diffstat (limited to 'ltm.c')
-rw-r--r--ltm.c22
1 files changed, 5 insertions, 17 deletions
diff --git a/ltm.c b/ltm.c
index d41ab98d..4b14f197 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 2.54 2017/12/19 16:40:17 roberto Exp roberto $ 2** $Id: ltm.c,v 2.55 2017/12/20 14:58:05 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*/
@@ -101,7 +101,7 @@ const char *luaT_objtypename (lua_State *L, const TValue *o) {
101 101
102void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 102void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,
103 const TValue *p2, const TValue *p3) { 103 const TValue *p2, const TValue *p3) {
104 StkId func = (isLuacode(L->ci)) ? L->ci->top : L->top; 104 StkId func = L->top;
105 setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ 105 setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */
106 setobj2s(L, func + 1, p1); /* 1st argument */ 106 setobj2s(L, func + 1, p1); /* 1st argument */
107 setobj2s(L, func + 2, p2); /* 2nd argument */ 107 setobj2s(L, func + 2, p2); /* 2nd argument */
@@ -115,8 +115,8 @@ void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,
115} 115}
116 116
117 117
118static void reallycallTMres (lua_State *L, const TValue *f, const TValue *p1, 118void luaT_callTMres (lua_State *L, const TValue *f, const TValue *p1,
119 const TValue *p2, StkId res) { 119 const TValue *p2, StkId res) {
120 ptrdiff_t result = savestack(L, res); 120 ptrdiff_t result = savestack(L, res);
121 StkId func = L->top; 121 StkId func = L->top;
122 setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ 122 setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */
@@ -133,29 +133,19 @@ static void reallycallTMres (lua_State *L, const TValue *f, const TValue *p1,
133} 133}
134 134
135 135
136void luaT_callTMres (lua_State *L, const TValue *f, const TValue *p1,
137 const TValue *p2, StkId res) {
138 if (isLuacode(L->ci))
139 L->top = L->ci->top; /* prepare top */
140 reallycallTMres(L, f, p1, p2, res);
141}
142
143
144static int callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 136static int callbinTM (lua_State *L, const TValue *p1, const TValue *p2,
145 StkId res, TMS event) { 137 StkId res, TMS event) {
146 const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ 138 const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */
147 if (ttisnil(tm)) 139 if (ttisnil(tm))
148 tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ 140 tm = luaT_gettmbyobj(L, p2, event); /* try second operand */
149 if (ttisnil(tm)) return 0; 141 if (ttisnil(tm)) return 0;
150 reallycallTMres(L, tm, p1, p2, res); 142 luaT_callTMres(L, tm, p1, p2, res);
151 return 1; 143 return 1;
152} 144}
153 145
154 146
155void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 147void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,
156 StkId res, TMS event) { 148 StkId res, TMS event) {
157 if (event != TM_CONCAT && isLuacode(L->ci))
158 L->top = L->ci->top; /* prepare top */
159 if (!callbinTM(L, p1, p2, res, event)) { 149 if (!callbinTM(L, p1, p2, res, event)) {
160 switch (event) { 150 switch (event) {
161 case TM_CONCAT: 151 case TM_CONCAT:
@@ -195,8 +185,6 @@ void luaT_trybiniTM (lua_State *L, const TValue *p1, int i2,
195 185
196int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, 186int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2,
197 TMS event) { 187 TMS event) {
198 if (isLuacode(L->ci))
199 L->top = L->ci->top; /* prepare top */
200 if (callbinTM(L, p1, p2, L->top, event)) /* try original event */ 188 if (callbinTM(L, p1, p2, L->top, event)) /* try original event */
201 return !l_isfalse(s2v(L->top)); 189 return !l_isfalse(s2v(L->top));
202 else if (event == TM_LE) { 190 else if (event == TM_LE) {