diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-04-25 13:07:52 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-04-25 13:07:52 -0300 |
| commit | 9600c60df3e5a971ca642734470901775ef67ff9 (patch) | |
| tree | e53e526676be089fde966143599f22c4a5e862fb /lvm.c | |
| parent | 32bf6c9b277d04a35591ca6420cf1518ebc1a7f3 (diff) | |
| download | lua-9600c60df3e5a971ca642734470901775ef67ff9.tar.gz lua-9600c60df3e5a971ca642734470901775ef67ff9.tar.bz2 lua-9600c60df3e5a971ca642734470901775ef67ff9.zip | |
functions 'get_equalTM' and 'call_orderTM' moved to other files
to make 'lvm.c' smaller
Diffstat (limited to '')
| -rw-r--r-- | lvm.c | 35 |
1 files changed, 6 insertions, 29 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.158 2013/04/16 18:43:05 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.159 2013/04/25 15:59:42 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -126,29 +126,6 @@ void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { | |||
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | 128 | ||
| 129 | static const TValue *get_equalTM (lua_State *L, Table *mt1, Table *mt2, | ||
| 130 | TMS event) { | ||
| 131 | const TValue *tm1 = fasttm(L, mt1, event); | ||
| 132 | const TValue *tm2; | ||
| 133 | if (tm1 == NULL) return NULL; /* no metamethod */ | ||
| 134 | if (mt1 == mt2) return tm1; /* same metatables => same metamethods */ | ||
| 135 | tm2 = fasttm(L, mt2, event); | ||
| 136 | if (tm2 == NULL) return NULL; /* no metamethod */ | ||
| 137 | if (luaV_rawequalobj(tm1, tm2)) /* same metamethods? */ | ||
| 138 | return tm1; | ||
| 139 | return NULL; | ||
| 140 | } | ||
| 141 | |||
| 142 | |||
| 143 | static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, | ||
| 144 | TMS event) { | ||
| 145 | if (!luaT_callbinTM(L, p1, p2, L->top, event)) | ||
| 146 | return -1; /* no metamethod */ | ||
| 147 | else | ||
| 148 | return !l_isfalse(L->top); | ||
| 149 | } | ||
| 150 | |||
| 151 | |||
| 152 | static int l_strcmp (const TString *ls, const TString *rs) { | 129 | static int l_strcmp (const TString *ls, const TString *rs) { |
| 153 | const char *l = getstr(ls); | 130 | const char *l = getstr(ls); |
| 154 | size_t ll = ls->tsv.len; | 131 | size_t ll = ls->tsv.len; |
| @@ -177,7 +154,7 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { | |||
| 177 | return luai_numlt(L, nvalue(l), nvalue(r)); | 154 | return luai_numlt(L, nvalue(l), nvalue(r)); |
| 178 | else if (ttisstring(l) && ttisstring(r)) | 155 | else if (ttisstring(l) && ttisstring(r)) |
| 179 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; | 156 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; |
| 180 | else if ((res = call_orderTM(L, l, r, TM_LT)) < 0) | 157 | else if ((res = luaT_callorderTM(L, l, r, TM_LT)) < 0) |
| 181 | luaG_ordererror(L, l, r); | 158 | luaG_ordererror(L, l, r); |
| 182 | return res; | 159 | return res; |
| 183 | } | 160 | } |
| @@ -189,9 +166,9 @@ int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { | |||
| 189 | return luai_numle(L, nvalue(l), nvalue(r)); | 166 | return luai_numle(L, nvalue(l), nvalue(r)); |
| 190 | else if (ttisstring(l) && ttisstring(r)) | 167 | else if (ttisstring(l) && ttisstring(r)) |
| 191 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; | 168 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; |
| 192 | else if ((res = call_orderTM(L, l, r, TM_LE)) >= 0) /* first try `le' */ | 169 | else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0) /* first try `le' */ |
| 193 | return res; | 170 | return res; |
| 194 | else if ((res = call_orderTM(L, r, l, TM_LT)) < 0) /* else try `lt' */ | 171 | else if ((res = luaT_callorderTM(L, r, l, TM_LT)) < 0) /* else try `lt' */ |
| 195 | luaG_ordererror(L, l, r); | 172 | luaG_ordererror(L, l, r); |
| 196 | return !res; | 173 | return !res; |
| 197 | } | 174 | } |
| @@ -221,13 +198,13 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { | |||
| 221 | case LUA_TUSERDATA: { | 198 | case LUA_TUSERDATA: { |
| 222 | if (uvalue(t1) == uvalue(t2)) return 1; | 199 | if (uvalue(t1) == uvalue(t2)) return 1; |
| 223 | else if (L == NULL) return 0; | 200 | else if (L == NULL) return 0; |
| 224 | tm = get_equalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, TM_EQ); | 201 | tm = luaT_getequalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable); |
| 225 | break; /* will try TM */ | 202 | break; /* will try TM */ |
| 226 | } | 203 | } |
| 227 | case LUA_TTABLE: { | 204 | case LUA_TTABLE: { |
| 228 | if (hvalue(t1) == hvalue(t2)) return 1; | 205 | if (hvalue(t1) == hvalue(t2)) return 1; |
| 229 | else if (L == NULL) return 0; | 206 | else if (L == NULL) return 0; |
| 230 | tm = get_equalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ); | 207 | tm = luaT_getequalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable); |
| 231 | break; /* will try TM */ | 208 | break; /* will try TM */ |
| 232 | } | 209 | } |
| 233 | default: | 210 | default: |
