diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-04-05 11:26:23 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-04-05 11:26:23 -0300 |
commit | 119d5e46d576c43bf8828b67092b3450a749af08 (patch) | |
tree | 8c80264aec03d5adf287f3fe720c00e4ddb49914 /lapi.c | |
parent | 83abbac946e965d9c36ca5054866e2693402318a (diff) | |
download | lua-119d5e46d576c43bf8828b67092b3450a749af08.tar.gz lua-119d5e46d576c43bf8828b67092b3450a749af08.tar.bz2 lua-119d5e46d576c43bf8828b67092b3450a749af08.zip |
lua_arith gets no fake operand for unary minus
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.143 2010/12/20 19:40:07 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.144 2010/12/29 18:00:23 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 | */ |
@@ -283,15 +283,23 @@ LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { | |||
283 | 283 | ||
284 | 284 | ||
285 | LUA_API void lua_arith (lua_State *L, int op) { | 285 | LUA_API void lua_arith (lua_State *L, int op) { |
286 | StkId o1; /* 1st operand */ | ||
287 | StkId o2; /* 2nd operand */ | ||
286 | lua_lock(L); | 288 | lua_lock(L); |
287 | api_checknelems(L, 2); | 289 | if (op != LUA_OPUNM) /* all other operations expect two operands */ |
288 | if (ttisnumber(L->top - 2) && ttisnumber(L->top - 1)) { | 290 | api_checknelems(L, 2); |
289 | changenvalue(L->top - 2, | 291 | else { /* for unary minus, add fake 2nd operand */ |
290 | luaO_arith(op, nvalue(L->top - 2), nvalue(L->top - 1))); | 292 | api_checknelems(L, 1); |
293 | setobjs2s(L, L->top, L->top - 1); | ||
294 | L->top++; | ||
295 | } | ||
296 | o1 = L->top - 2; | ||
297 | o2 = L->top - 1; | ||
298 | if (ttisnumber(o1) && ttisnumber(o2)) { | ||
299 | changenvalue(o1, luaO_arith(op, nvalue(o1), nvalue(o2))); | ||
291 | } | 300 | } |
292 | else | 301 | else |
293 | luaV_arith(L, L->top - 2, L->top - 2, L->top - 1, | 302 | luaV_arith(L, o1, o1, o2, cast(TMS, op - LUA_OPADD + TM_ADD)); |
294 | cast(TMS, op - LUA_OPADD + TM_ADD)); | ||
295 | L->top--; | 303 | L->top--; |
296 | lua_unlock(L); | 304 | lua_unlock(L); |
297 | } | 305 | } |