diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-02-22 16:12:46 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-02-22 16:12:46 -0200 |
| commit | 4d4e6f07c022f94999c52fb593a20fce85c5092a (patch) | |
| tree | 538175d34df7d5fb0a24c6c4c03b07b34f8d2665 /ltm.c | |
| parent | 5cecf0ea9f14d9ea5363654c429c3fd7d2c0e1a7 (diff) | |
| download | lua-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.c | 40 |
1 files changed, 26 insertions, 14 deletions
| @@ -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 | ||
| 20 | const char *const luaT_eventname[] = { /* ORDER IM */ | 20 | const 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 */ |
| 40 | static const char luaT_validevents[NUM_TAGS][IM_N] = { | 39 | static 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 | ||
| 50 | int luaT_validevent (int t, int e) { /* ORDER LUA_T */ | 49 | int luaT_validevent (int t, int e) { /* ORDER LUA_T */ |
| @@ -122,7 +121,13 @@ int luaT_effectivetag (const TObject *o) { | |||
| 122 | 121 | ||
| 123 | 122 | ||
| 124 | const TObject *luaT_gettagmethod (lua_State *L, int t, const char *event) { | 123 | const 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 | ||
| 134 | void luaT_settagmethod (lua_State *L, int t, const char *event, TObject *func) { | 139 | void 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 | ||
| 149 | const char *luaT_travtagmethods (lua_State *L, int (*fn)(lua_State *, TObject *)) { /* ORDER IM */ | 160 | const 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; |
