[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: A ping for __tonumber
- From: Andrew Starks <andrew.starks@...>
- Date: Fri, 26 Jul 2013 10:17:26 -0500
I've gone over the archives and read past posts on the __tonumber
metamethod idea. In light of work on 5.3, I wanted to throw out that
__tonumber would be welcomed.
Within my own Lua code, I often want to turn an object into a plain
number. The meta-methods can effectively do most of what I want, but
not when I'm dealing with relational operators when one side of is an
actual number.
`tonumber` might be more appropriate than going through the work of
defining every arithmetic metamethod that I may or may not need for
that object (it's tedious).
Finally, __tonumber just feels... missing. I even had to triple check
that it wasn't in 5.2, lest I embarrass myself. :)
Of course, I'm happy to monkeypatch tonumber (and may apply the power
patch that I found in my research). My opinion is that it would be
generally helpful, especially when/if coercion of strings to numbers
should go away[1].
-Andrew
[1]I'm in the habit of calling tonumber whenever I need a number, in
case I get a string. I use it as a silent protest that Lua coerces
strings without me asking.