diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-04-26 16:51:17 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-04-26 16:51:17 -0300 |
| commit | 360587f31959b9a112b13000b3c7ee8ae51cf146 (patch) | |
| tree | 800c578cf9a945c336cd8a251aa61c792c76ce0c /lapi.c | |
| parent | eee51492e26bc295d2b67b91aa7bdb97a21e3623 (diff) | |
| download | lua-360587f31959b9a112b13000b3c7ee8ae51cf146.tar.gz lua-360587f31959b9a112b13000b3c7ee8ae51cf146.tar.bz2 lua-360587f31959b9a112b13000b3c7ee8ae51cf146.zip | |
favoring 'tonumber' over 'nvalue'
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 7 |
1 files changed, 4 insertions, 3 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.175 2013/04/26 15:39:25 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.176 2013/04/26 16:03:50 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 | */ |
| @@ -299,6 +299,7 @@ LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { | |||
| 299 | LUA_API void lua_arith (lua_State *L, int op) { | 299 | LUA_API void lua_arith (lua_State *L, int op) { |
| 300 | StkId o1; /* 1st operand */ | 300 | StkId o1; /* 1st operand */ |
| 301 | StkId o2; /* 2nd operand */ | 301 | StkId o2; /* 2nd operand */ |
| 302 | lua_Number n1, n2; | ||
| 302 | lua_lock(L); | 303 | lua_lock(L); |
| 303 | if (op != LUA_OPUNM) /* all other operations expect two operands */ | 304 | if (op != LUA_OPUNM) /* all other operations expect two operands */ |
| 304 | api_checknelems(L, 2); | 305 | api_checknelems(L, 2); |
| @@ -309,8 +310,8 @@ LUA_API void lua_arith (lua_State *L, int op) { | |||
| 309 | } | 310 | } |
| 310 | o1 = L->top - 2; | 311 | o1 = L->top - 2; |
| 311 | o2 = L->top - 1; | 312 | o2 = L->top - 1; |
| 312 | if (ttisnumber(o1) && ttisnumber(o2)) { | 313 | if (tonumber(o1, &n1) && tonumber(o2, &n2)) { |
| 313 | setnvalue(o1, luaO_arith(op, nvalue(o1), nvalue(o2))); | 314 | setnvalue(o1, luaO_arith(op, n1, n2)); |
| 314 | } | 315 | } |
| 315 | else | 316 | else |
| 316 | luaV_arith(L, o1, o1, o2, cast(TMS, op - LUA_OPADD + TM_ADD)); | 317 | luaV_arith(L, o1, o1, o2, cast(TMS, op - LUA_OPADD + TM_ADD)); |
