diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-11-19 13:05:15 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-11-19 13:05:15 -0200 |
commit | 5d628519d37a70b56be610cc4c256b3accc2f72c (patch) | |
tree | a529e8781147c939672d780a58d53f0b8864419e | |
parent | 244646bdf7ed8b9c01e93213337b1ab0547ceb1c (diff) | |
download | lua-5d628519d37a70b56be610cc4c256b3accc2f72c.tar.gz lua-5d628519d37a70b56be610cc4c256b3accc2f72c.tar.bz2 lua-5d628519d37a70b56be610cc4c256b3accc2f72c.zip |
simpler definition for 'luaV_tonumber_'
-rw-r--r-- | lvm.c | 19 |
1 files changed, 8 insertions, 11 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.227 2014/11/02 19:19:04 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.228 2014/11/03 20:07:47 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 | */ |
@@ -63,26 +63,23 @@ static int tofloat (const TValue *obj, lua_Number *n) { | |||
63 | 63 | ||
64 | 64 | ||
65 | /* | 65 | /* |
66 | ** Try to convert a value to a float. Check 'isinteger' first, because | 66 | ** Try to convert a value to a float. The float case is already handled |
67 | ** in general the float case is already handled by the macro 'tonumber'. | 67 | ** by the macro 'tonumber'. |
68 | */ | 68 | */ |
69 | int luaV_tonumber_ (const TValue *obj, lua_Number *n) { | 69 | int luaV_tonumber_ (const TValue *obj, lua_Number *n) { |
70 | TValue v; | 70 | TValue v; |
71 | again: | ||
72 | if (ttisinteger(obj)) { | 71 | if (ttisinteger(obj)) { |
73 | *n = cast_num(ivalue(obj)); | 72 | *n = cast_num(ivalue(obj)); |
74 | return 1; | 73 | return 1; |
75 | } | 74 | } |
76 | else if (ttisfloat(obj)) { | ||
77 | *n = fltvalue(obj); | ||
78 | return 1; | ||
79 | } | ||
80 | else if (cvt2num(obj) && /* string convertible to number? */ | 75 | else if (cvt2num(obj) && /* string convertible to number? */ |
81 | luaO_str2num(svalue(obj), &v) == tsvalue(obj)->len + 1) { | 76 | luaO_str2num(svalue(obj), &v) == tsvalue(obj)->len + 1) { |
82 | obj = &v; | 77 | /* convert result of 'luaO_str2num' to a float */ |
83 | goto again; /* convert result from 'luaO_str2num' to a float */ | 78 | *n = (ttisinteger(&v)) ? cast_num(ivalue(&v)) : fltvalue(&v); |
79 | return 1; | ||
84 | } | 80 | } |
85 | return 0; /* conversion failed */ | 81 | else |
82 | return 0; /* conversion failed */ | ||
86 | } | 83 | } |
87 | 84 | ||
88 | 85 | ||