aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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