Log In  


The documentation says tonum(val) returns nil if the conversion fails, but it actually returns nothing. Tested in 0.1.11d.

1


Seems to work ok:

local r=tonum("sdfds")
if r==nil then
	print("r is nil")
else
	assert("should not be there")
end

r is set to nil even when the function does not return anything. Instead, try the following:

print(type(nil))
print(type(tonum("sdfds")))

Agreed that either the docs or the function should be fixed. Lua does treat "no return value" and "returns nil" as distinct. Official Lua's tonumber() returns nil.

print(tostr(nil))           -- "[nil]"
print(tostr(tonum('xyz'))   -- "[no value]"


[Please log in to post a comment]