aboutsummaryrefslogtreecommitdiff
path: root/ltm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-02-22 16:12:46 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-02-22 16:12:46 -0200
commit4d4e6f07c022f94999c52fb593a20fce85c5092a (patch)
tree538175d34df7d5fb0a24c6c4c03b07b34f8d2665 /ltm.c
parent5cecf0ea9f14d9ea5363654c429c3fd7d2c0e1a7 (diff)
downloadlua-4d4e6f07c022f94999c52fb593a20fce85c5092a.tar.gz
lua-4d4e6f07c022f94999c52fb593a20fce85c5092a.tar.bz2
lua-4d4e6f07c022f94999c52fb593a20fce85c5092a.zip
all order operators use a single tag method (<)
Diffstat (limited to 'ltm.c')
-rw-r--r--ltm.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/ltm.c b/ltm.c
index 93a806d8..f9812bc9 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 1.30 1999/12/23 18:19:57 roberto Exp roberto $ 2** $Id: ltm.c,v 1.31 2000/01/19 12:00:45 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,9 +18,8 @@
18 18
19 19
20const char *const luaT_eventname[] = { /* ORDER IM */ 20const char *const luaT_eventname[] = { /* ORDER IM */
21 "gettable", "settable", "index", "getglobal", "setglobal", "add", 21 "gettable", "settable", "index", "getglobal", "setglobal", "add", "sub",
22 "sub", "mul", "div", "pow", "unm", "lt", "le", "gt", "ge", 22 "mul", "div", "pow", "unm", "lt", "concat", "gc", "function", NULL
23 "concat", "gc", "function", NULL
24}; 23};
25 24
26 25
@@ -38,13 +37,13 @@ static int luaI_checkevent (lua_State *L, const char *name, const char *const li
38*/ 37*/
39/* ORDER LUA_T, ORDER IM */ 38/* ORDER LUA_T, ORDER IM */
40static const char luaT_validevents[NUM_TAGS][IM_N] = { 39static const char luaT_validevents[NUM_TAGS][IM_N] = {
41{1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_T_USERDATA */ 40{1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_T_USERDATA */
42{1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_NUMBER */ 41{1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, /* LUA_T_NUMBER */
43{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_STRING */ 42{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_STRING */
44{0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_T_ARRAY */ 43{0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_T_ARRAY */
45{1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_LPROTO */ 44{1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_LPROTO */
46{1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_CPROTO */ 45{1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_CPROTO */
47{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* LUA_T_NIL */ 46{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* LUA_T_NIL */
48}; 47};
49 48
50int luaT_validevent (int t, int e) { /* ORDER LUA_T */ 49int luaT_validevent (int t, int e) { /* ORDER LUA_T */
@@ -122,7 +121,13 @@ int luaT_effectivetag (const TObject *o) {
122 121
123 122
124const TObject *luaT_gettagmethod (lua_State *L, int t, const char *event) { 123const TObject *luaT_gettagmethod (lua_State *L, int t, const char *event) {
125 int e = luaI_checkevent(L, event, luaT_eventname); 124 int e;
125#ifdef LUA_COMPAT_ORDER_TM
126 static const char *old_order[] = {"le", "gt", "ge", NULL};
127 if (luaL_findstring(event, old_order) >= 0)
128 return &luaO_nilobject;
129#endif
130 e = luaI_checkevent(L, event, luaT_eventname);
126 checktag(L, t); 131 checktag(L, t);
127 if (luaT_validevent(t, e)) 132 if (luaT_validevent(t, e))
128 return luaT_getim(L, t,e); 133 return luaT_getim(L, t,e);
@@ -133,7 +138,13 @@ const TObject *luaT_gettagmethod (lua_State *L, int t, const char *event) {
133 138
134void luaT_settagmethod (lua_State *L, int t, const char *event, TObject *func) { 139void luaT_settagmethod (lua_State *L, int t, const char *event, TObject *func) {
135 TObject temp; 140 TObject temp;
136 int e = luaI_checkevent(L, event, luaT_eventname); 141 int e;
142#ifdef LUA_COMPAT_ORDER_TM
143 static const char *old_order[] = {"le", "gt", "ge", NULL};
144 if (luaL_findstring(event, old_order) >= 0)
145 return; /* do nothing for old operators */
146#endif
147 e = luaI_checkevent(L, event, luaT_eventname);
137 checktag(L, t); 148 checktag(L, t);
138 if (!luaT_validevent(t, e)) 149 if (!luaT_validevent(t, e))
139 luaL_verror(L, "cannot change tag method `%.20s' for type `%.20s'%.20s", 150 luaL_verror(L, "cannot change tag method `%.20s' for type `%.20s'%.20s",
@@ -146,7 +157,8 @@ void luaT_settagmethod (lua_State *L, int t, const char *event, TObject *func) {
146} 157}
147 158
148 159
149const char *luaT_travtagmethods (lua_State *L, int (*fn)(lua_State *, TObject *)) { /* ORDER IM */ 160const char *luaT_travtagmethods (lua_State *L,
161 int (*fn)(lua_State *, TObject *)) { /* ORDER IM */
150 int e; 162 int e;
151 for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { 163 for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) {
152 int t; 164 int t;