aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-11-19 13:05:15 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-11-19 13:05:15 -0200
commit5d628519d37a70b56be610cc4c256b3accc2f72c (patch)
treea529e8781147c939672d780a58d53f0b8864419e
parent244646bdf7ed8b9c01e93213337b1ab0547ceb1c (diff)
downloadlua-5d628519d37a70b56be610cc4c256b3accc2f72c.tar.gz
lua-5d628519d37a70b56be610cc4c256b3accc2f72c.tar.bz2
lua-5d628519d37a70b56be610cc4c256b3accc2f72c.zip
simpler definition for 'luaV_tonumber_'
-rw-r--r--lvm.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/lvm.c b/lvm.c
index ba4bf398..28a3aab8 100644
--- a/lvm.c
+++ b/lvm.c
@@ -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*/
69int luaV_tonumber_ (const TValue *obj, lua_Number *n) { 69int 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