浏览代码

new function 'luaT_trybinTM'

Roberto Ierusalimschy 12 年之前
父节点
当前提交
b4be507578
共有 2 个文件被更改,包括 16 次插入2 次删除
  1. 13 1
      ltm.c
  2. 3 1
      ltm.h

+ 13 - 1
ltm.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ltm.c,v 2.17 2013/04/25 16:07:52 roberto Exp roberto $
+** $Id: ltm.c,v 2.18 2013/04/26 13:07:53 roberto Exp roberto $
 ** Tag methods
 ** Tag methods
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -12,6 +12,7 @@
 
 
 #include "lua.h"
 #include "lua.h"
 
 
+#include "ldebug.h"
 #include "ldo.h" 
 #include "ldo.h" 
 #include "lobject.h"
 #include "lobject.h"
 #include "lstate.h"
 #include "lstate.h"
@@ -106,6 +107,17 @@ int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2,
 }
 }
 
 
 
 
+void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,
+                    StkId res, TMS event) {
+  if (!luaT_callbinTM(L, p1, p2, res, event)) {
+    if (event == TM_CONCAT)
+      luaG_concaterror(L, p1, p2);
+    else
+      luaG_aritherror(L, p1, p2);
+  }
+}
+
+
 const TValue *luaT_getequalTM (lua_State *L, Table *mt1, Table *mt2) {
 const TValue *luaT_getequalTM (lua_State *L, Table *mt1, Table *mt2) {
   const TValue *tm1 = fasttm(L, mt1, TM_EQ);
   const TValue *tm1 = fasttm(L, mt1, TM_EQ);
   const TValue *tm2;
   const TValue *tm2;

+ 3 - 1
ltm.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ltm.h,v 2.14 2013/04/25 16:07:52 roberto Exp roberto $
+** $Id: ltm.h,v 2.15 2013/04/26 13:07:53 roberto Exp roberto $
 ** Tag methods
 ** Tag methods
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -59,6 +59,8 @@ LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,
                             const TValue *p2, TValue *p3, int hasres);
                             const TValue *p2, TValue *p3, int hasres);
 LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2,
 LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2,
                               StkId res, TMS event);
                               StkId res, TMS event);
+LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,
+                              StkId res, TMS event);
 LUAI_FUNC const TValue *luaT_getequalTM (lua_State *L, Table *mt1, Table *mt2);
 LUAI_FUNC const TValue *luaT_getequalTM (lua_State *L, Table *mt1, Table *mt2);
 LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1,
 LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1,
                                 const TValue *p2, TMS event);
                                 const TValue *p2, TMS event);