commit 5d628519d37a70b56be610cc4c256b3accc2f72c
parent 244646bdf7ed8b9c01e93213337b1ab0547ceb1c
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Wed, 19 Nov 2014 13:04:50 -0200
simpler definition for 'luaV_tonumber_'
Diffstat:
M | lvm.c | | | 19 | ++++++++----------- |
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/lvm.c b/lvm.c
@@ -1,5 +1,5 @@
/*
-** $Id: lvm.c,v 2.227 2014/11/02 19:19:04 roberto Exp roberto $
+** $Id: lvm.c,v 2.228 2014/11/03 20:07:47 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -63,26 +63,23 @@ static int tofloat (const TValue *obj, lua_Number *n) {
/*
-** Try to convert a value to a float. Check 'isinteger' first, because
-** in general the float case is already handled by the macro 'tonumber'.
+** Try to convert a value to a float. The float case is already handled
+** by the macro 'tonumber'.
*/
int luaV_tonumber_ (const TValue *obj, lua_Number *n) {
TValue v;
- again:
if (ttisinteger(obj)) {
*n = cast_num(ivalue(obj));
return 1;
}
- else if (ttisfloat(obj)) {
- *n = fltvalue(obj);
- return 1;
- }
else if (cvt2num(obj) && /* string convertible to number? */
luaO_str2num(svalue(obj), &v) == tsvalue(obj)->len + 1) {
- obj = &v;
- goto again; /* convert result from 'luaO_str2num' to a float */
+ /* convert result of 'luaO_str2num' to a float */
+ *n = (ttisinteger(&v)) ? cast_num(ivalue(&v)) : fltvalue(&v);
+ return 1;
}
- return 0; /* conversion failed */
+ else
+ return 0; /* conversion failed */
}