diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-12-19 11:36:32 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-12-19 11:36:32 -0200 |
commit | 2b83711fbac0509a40cfb616b9a68bdf683e8471 (patch) | |
tree | 1f244bc08de68b01df8b9d2ff558558703a1a6bb | |
parent | 3ae21a352c4cad550a97974c68cd57c3abc39570 (diff) | |
download | lua-2b83711fbac0509a40cfb616b9a68bdf683e8471.tar.gz lua-2b83711fbac0509a40cfb616b9a68bdf683e8471.tar.bz2 lua-2b83711fbac0509a40cfb616b9a68bdf683e8471.zip |
new macro 'nvalue' (to convert an object to a float when we know
object is a number)
-rw-r--r-- | lcode.c | 8 | ||||
-rw-r--r-- | lobject.h | 4 | ||||
-rw-r--r-- | lvm.c | 5 |
3 files changed, 7 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 2.96 2014/11/21 12:15:57 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.97 2014/11/24 14:59:22 roberto Exp roberto $ |
3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -761,12 +761,8 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { | |||
761 | ** return false if folding can raise an error | 761 | ** return false if folding can raise an error |
762 | */ | 762 | */ |
763 | static int validop (int op, TValue *v1, TValue *v2) { | 763 | static int validop (int op, TValue *v1, TValue *v2) { |
764 | lua_Number a, b; | ||
765 | lua_Integer i; | 764 | lua_Integer i; |
766 | cast_void(a); cast_void(b); /* macro may not use its arguments */ | 765 | if (luai_numinvalidop(op, nvalue(v1), nvalue(v2))) return 0; |
767 | if (luai_numinvalidop(op, (cast_void(tonumber(v1, &a)), a), | ||
768 | (cast_void(tonumber(v2, &b)), b))) | ||
769 | return 0; | ||
770 | switch (op) { | 766 | switch (op) { |
771 | case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR: | 767 | case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR: |
772 | case LUA_OPSHL: case LUA_OPSHR: case LUA_OPBNOT: /* conversion errors */ | 768 | case LUA_OPSHL: case LUA_OPSHR: case LUA_OPBNOT: /* conversion errors */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 2.103 2014/10/01 11:52:33 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.104 2014/10/25 11:50:46 roberto Exp roberto $ |
3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -154,6 +154,8 @@ typedef struct lua_TValue TValue; | |||
154 | /* Macros to access values */ | 154 | /* Macros to access values */ |
155 | #define ivalue(o) check_exp(ttisinteger(o), val_(o).i) | 155 | #define ivalue(o) check_exp(ttisinteger(o), val_(o).i) |
156 | #define fltvalue(o) check_exp(ttisfloat(o), val_(o).n) | 156 | #define fltvalue(o) check_exp(ttisfloat(o), val_(o).n) |
157 | #define nvalue(o) check_exp(ttisnumber(o), \ | ||
158 | (ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o))) | ||
157 | #define gcvalue(o) check_exp(iscollectable(o), val_(o).gc) | 159 | #define gcvalue(o) check_exp(iscollectable(o), val_(o).gc) |
158 | #define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p) | 160 | #define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p) |
159 | #define tsvalue(o) check_exp(ttisstring(o), gco2ts(val_(o).gc)) | 161 | #define tsvalue(o) check_exp(ttisstring(o), gco2ts(val_(o).gc)) |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.229 2014/11/19 15:05:15 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.230 2014/11/21 12:15:00 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 | */ |
@@ -74,8 +74,7 @@ int luaV_tonumber_ (const TValue *obj, lua_Number *n) { | |||
74 | } | 74 | } |
75 | else if (cvt2num(obj) && /* string convertible to number? */ | 75 | else if (cvt2num(obj) && /* string convertible to number? */ |
76 | luaO_str2num(svalue(obj), &v) == tsvalue(obj)->len + 1) { | 76 | luaO_str2num(svalue(obj), &v) == tsvalue(obj)->len + 1) { |
77 | /* convert result of 'luaO_str2num' to a float */ | 77 | *n = nvalue(&v); /* convert result of 'luaO_str2num' to a float */ |
78 | *n = (ttisinteger(&v)) ? cast_num(ivalue(&v)) : fltvalue(&v); | ||
79 | return 1; | 78 | return 1; |
80 | } | 79 | } |
81 | else | 80 | else |