aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-07-30 11:42:44 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-07-30 11:42:44 -0300
commitd86170662017645cf22884641f33a9d6b48d16e6 (patch)
tree80782cb7bfc8c31a0f6068f99ff47c0ca705b591
parent34ac039fb84e3c12fb8c96c9c99c34224c09872b (diff)
downloadlua-d86170662017645cf22884641f33a9d6b48d16e6.tar.gz
lua-d86170662017645cf22884641f33a9d6b48d16e6.tar.bz2
lua-d86170662017645cf22884641f33a9d6b48d16e6.zip
new macro 'cvt2num' to better control whether strings are convertible
to numbers
-rw-r--r--lvm.c6
-rw-r--r--lvm.h23
2 files changed, 18 insertions, 11 deletions
diff --git a/lvm.c b/lvm.c
index 89ef8997..2719bb20 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.220 2014/07/21 16:02:10 roberto Exp roberto $ 2** $Id: lvm.c,v 2.221 2014/07/30 14:00:14 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*/
@@ -66,7 +66,7 @@ int luaV_tonumber_ (const TValue *obj, lua_Number *n) {
66 *n = fltvalue(obj); 66 *n = fltvalue(obj);
67 return 1; 67 return 1;
68 } 68 }
69 else if (ttisstring(obj) && /* string convertible to number? */ 69 else if (cvt2num(obj) && /* string convertible to number? */
70 luaO_str2num(svalue(obj), &v) == tsvalue(obj)->len + 1) { 70 luaO_str2num(svalue(obj), &v) == tsvalue(obj)->len + 1) {
71 obj = &v; 71 obj = &v;
72 goto again; /* convert result from 'luaO_str2num' to a float */ 72 goto again; /* convert result from 'luaO_str2num' to a float */
@@ -98,7 +98,7 @@ static int tointeger_aux (const TValue *obj, lua_Integer *p, int mode) {
98 *p = ivalue(obj); 98 *p = ivalue(obj);
99 return 1; 99 return 1;
100 } 100 }
101 else if (ttisstring(obj) && 101 else if (cvt2num(obj) &&
102 luaO_str2num(svalue(obj), &v) == tsvalue(obj)->len + 1) { 102 luaO_str2num(svalue(obj), &v) == tsvalue(obj)->len + 1) {
103 obj = &v; 103 obj = &v;
104 goto again; /* convert result from 'luaO_str2num' to an integer */ 104 goto again; /* convert result from 'luaO_str2num' to an integer */
diff --git a/lvm.h b/lvm.h
index 0a4984cb..86fb874c 100644
--- a/lvm.h
+++ b/lvm.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.h,v 2.31 2014/05/26 17:10:22 roberto Exp roberto $ 2** $Id: lvm.h,v 2.32 2014/07/30 14:00:14 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*/
@@ -13,6 +13,20 @@
13#include "ltm.h" 13#include "ltm.h"
14 14
15 15
16#if !defined(LUA_NOCVTN2S)
17#define cvt2str(o) ttisnumber(o)
18#else
19#define cvt2str(o) 0 /* no convertion from numbers to strings */
20#endif
21
22
23#if !defined(LUA_NOCVTS2N)
24#define cvt2num(o) ttisstring(o)
25#else
26#define cvt2num(o) 0 /* no convertion from strings to numbers */
27#endif
28
29
16#define tonumber(o,n) \ 30#define tonumber(o,n) \
17 (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) 31 (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))
18 32
@@ -24,13 +38,6 @@
24#define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) 38#define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2)
25 39
26 40
27#if !defined(LUA_NOCVTN2S)
28#define cvt2str(o) ttisnumber(o)
29#else
30#define cvt2str(o) 0 /* no convertion from numbers to strings */
31#endif
32
33
34LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); 41LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2);
35LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 42LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
36LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 43LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r);