Browse Source

Removed some wrong comments

Both 'tonumber' and 'tointeger' cannot change the out parameter when
the conversion fails.
Roberto Ierusalimschy 5 years ago
parent
commit
508a705c1c
1 changed files with 6 additions and 8 deletions
  1. 6 8
      lapi.c

+ 6 - 8
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;
 }