No support from me, as this would cause major issues with future bugs that may not be apparent right away for anyone who is either new to Roblox Lua or an experienced vanilla (or other) Lua scripter.
This would also mean adding extra tests to the arithmetic opcodes in the vm which could potentially make large calculations slower than they already are.
Treating booleans loosely as numbers is a mistake, and that’s why recent languages don’t allow you to do this.
If an if statement for doing something conditionally is burdensome, you’re doing something wrong.
There’s several trivial solutions you can do in your own code without adding a footgun to the language:
local N = {
[true] = 1,
[false] = 0,
}
......
something = something + N[bool]
This isn’t exactly correct. In C, 0 is used to mean false, but anything not 0 (1, -1, 42, etc) can represent true. I would imagine change would cause other problems as stated above.
There is a reason why C++ introduced true and false as fundamental datatypes: to exterminate the existing implicit type coercion present in C regarding bools and integers.
There has been really bad cases of developers doing things they shouldn’t be doing to C bools, such as int ops, and some really messed up code was given birth due to that.
something = something + bool
Is a perfect example of that. It’s as bad as spamming gotos, in the sense that it makes the code unreadable for literally everyone - even the programmer itself.
The problem is that in Lua, the only ‘false’ values are false and nil. If false becomes 0, then false becomes true as it is not nil. Any boolean value (such as .Changed listens to or the booleans in humanoids) would never return false, in turn breaking mostly any logic relying on humanoids and boolvalues.
While I don’t support this idea, I am curious as to what brought you to this statement. What is the use case for this feature request and where exactly would you need this?
JavaScript does some implicit casting that allows adding true and 1 but the whole language is built that way. Lua is not built that way. I don’t think it makes any sense for Roblox to fundamentally change how Lua handles types and I don’t think Roblox would want to either.
Could you not just write your own tonumber function for that?
local tonumberReal = tonumber
local function tonumber(n)
return if n == true then 1 elseif n == false then 0 else tonumberReal(n)
end
The issue here is that changing the way builtin functions work doesn’t guarantee backwards compatibility. Even if the cases of relying on tonumber(bool) to return nil are rare, I am sure there are at least a few cases.