commit 508a705c1c08d883473199d6ba019d186c28b9df
parent 6f1c033d72af8fe65bb67e17a242314b6aeb182f
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Thu, 28 Nov 2019 18:09:59 -0300
Removed some wrong comments
Both 'tonumber' and 'tointeger' cannot change the out parameter when
the conversion fails.
Diffstat:
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/lapi.c b/lapi.c
@@ -350,23 +350,21 @@ LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) {
LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) {
- lua_Number n;
+ lua_Number n = 0;
const TValue *o = index2value(L, idx);
int isnum = tonumber(o, &n);
- if (!isnum)
- n = 0; /* call to 'tonumber' may change 'n' even if it fails */
- if (pisnum) *pisnum = isnum;
+ if (pisnum)
+ *pisnum = isnum;
return n;
}
LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) {
- lua_Integer res;
+ lua_Integer res = 0;
const TValue *o = index2value(L, idx);
int isnum = tointeger(o, &res);
- if (!isnum)
- res = 0; /* call to 'tointeger' may change 'n' even if it fails */
- if (pisnum) *pisnum = isnum;
+ if (pisnum)
+ *pisnum = isnum;
return res;
}