coercion string->number in arithmetic operations moved to string

library
This commit is contained in:
Roberto Ierusalimschy
2017-07-07 13:34:32 -03:00
parent 07db10813c
commit 4dff277255
5 changed files with 111 additions and 19 deletions

12
lvm.h
View File

@@ -1,5 +1,5 @@
/*
** $Id: lvm.h,v 2.44 2017/06/09 19:16:41 roberto Exp roberto $
** $Id: lvm.h,v 2.45 2017/06/29 15:06:44 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -37,12 +37,22 @@
#endif
/* convert an object to a float (including string coercion) */
#define tonumber(o,n) \
(ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))
/* convert an object to a float (without string coercion) */
#define tonumberns(o,n) \
(ttisfloat(o) ? ((n) = fltvalue(o), 1) : \
(ttisinteger(o) ? ((n) = cast_num(ivalue(o)), 1) : 0))
/* convert an object to an integer (including string coercion) */
#define tointeger(o,i) \
(ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I))
#define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2))
#define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2)