diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-06-17 14:53:14 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-06-17 14:53:14 -0300 |
commit | 6980cb1aa7bb0238b9cb916320b0c6365bfbb10e (patch) | |
tree | 70d14f0d45e4d002d302a9f5404feff3e20c0c53 /lapi.c | |
parent | 59a59fafc6693e0f2656b59a1b278f6ca89d64cf (diff) | |
download | lua-6980cb1aa7bb0238b9cb916320b0c6365bfbb10e.tar.gz lua-6980cb1aa7bb0238b9cb916320b0c6365bfbb10e.tar.bz2 lua-6980cb1aa7bb0238b9cb916320b0c6365bfbb10e.zip |
new functions 'lua_arith' and 'lua_compare'
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 28 |
1 files changed, 15 insertions, 13 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.78 2009/06/01 19:09:26 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.79 2009/06/15 19:51:31 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -275,32 +275,34 @@ LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { | |||
275 | } | 275 | } |
276 | 276 | ||
277 | 277 | ||
278 | LUA_API int lua_equal (lua_State *L, int index1, int index2) { | 278 | LUA_API void lua_arith (lua_State *L, int op) { |
279 | StkId o1, o2; | 279 | lua_lock(L); |
280 | int i; | 280 | api_checknelems(L, 2); |
281 | lua_lock(L); /* may call tag method */ | 281 | luaV_arith(L, L->top - 2, L->top - 2, L->top - 1, op - LUA_OPADD + TM_ADD); |
282 | o1 = index2adr(L, index1); | 282 | L->top--; |
283 | o2 = index2adr(L, index2); | ||
284 | i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2); | ||
285 | lua_unlock(L); | 283 | lua_unlock(L); |
286 | return i; | ||
287 | } | 284 | } |
288 | 285 | ||
289 | 286 | ||
290 | LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { | 287 | LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { |
291 | StkId o1, o2; | 288 | StkId o1, o2; |
292 | int i; | 289 | int i; |
293 | lua_lock(L); /* may call tag method */ | 290 | lua_lock(L); /* may call tag method */ |
294 | o1 = index2adr(L, index1); | 291 | o1 = index2adr(L, index1); |
295 | o2 = index2adr(L, index2); | 292 | o2 = index2adr(L, index2); |
296 | i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 | 293 | if (o1 == luaO_nilobject || o2 == luaO_nilobject) |
297 | : luaV_lessthan(L, o1, o2); | 294 | i = 0; |
295 | else switch (op) { | ||
296 | case LUA_OPEQ: i = equalobj(L, o1, o2); break; | ||
297 | case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break; | ||
298 | case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break; | ||
299 | default: api_check(L, 0); i = 0; | ||
300 | } | ||
298 | lua_unlock(L); | 301 | lua_unlock(L); |
299 | return i; | 302 | return i; |
300 | } | 303 | } |
301 | 304 | ||
302 | 305 | ||
303 | |||
304 | LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { | 306 | LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { |
305 | TValue n; | 307 | TValue n; |
306 | const TValue *o = index2adr(L, idx); | 308 | const TValue *o = index2adr(L, idx); |