Anonymous

Module:Shared: Difference between revisions

From Melvor Idle
m
Add functions for parsing numbers
(Move getNamespacedID & getLocalID from Module:GameData, such that modules don't have to require an expensive module to use these functions)
m (Add functions for parsing numbers)
Tag: Reverted
Line 456: Line 456:
end
end
return namespace, localID
return namespace, localID
end
-- Converts a string to a numeric value, or the default value if the
-- string isn't a number.
function p.toNumberOrDefault(str, def)
local num = tonumber(str)
if num then
return num
else
return def
end
end
-- Attempts to convert a string to a numeric value.
-- Throws an error if the value isn't a number.
function p.toNumberOrError(str, errorMsg)
local num = tonumber(str)
local msg = errorMsg
if msg == nil then
msg = "NaN"
end
if num then
return num
else
error(msg)
end
end
end


return p
return p
2,875

edits