lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Chris Marrin wrote:
Lua has a very nice tostring() function, which can use a "__tostring" metamethod to give string conversion support to any user defined type. And tonumber() exists in 5.1, but its implementation does not include a "__tonumber" metamethod call. It simply converts a number or string to a number. Everything else returns nil. So, the first question is, why not make the implementation of tonumber() parallel to that of tostring()?

And the related question is, why not have a toboolean() as well, with the same sort of __toboolean metamethod?

I've implemented these - they're a little hairy. They also require extensive changes to the statements and standard libraries so they don't cause errors during type checking.

--
Lisa