From 5d628519d37a70b56be610cc4c256b3accc2f72c Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 19 Nov 2014 13:05:15 -0200 Subject: simpler definition for 'luaV_tonumber_' --- lvm.c | 19 ++++++++----------- 1 file 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 @@ /* -** $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 */ } -- cgit v1.2.3-55-g6feb