[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: __tonumber metamethod (was Re: Exposure of nil to end-users)
- From: Michal Kolodziejczyk <miko@...>
- Date: Thu, 05 Feb 2009 19:04:24 +0100
Doug Rogers wrote:
> Michal Kolodziejczyk wrote:
>> I am also missing __tonumber metamethod...
> It seems like this could be a useful feature, but if it were to behave
> like __tostring it would be of limited value - limited to programmers
> calling tonumber() explicitly.
Yes, I am aware of that, and this is what I meant - use __tonumber only
when explicity calling tonumber() (and maybe adding an optional number
base as a second argument to __tonumber). I did not mean to change the
internals of VM (as I also appreciate the simplicity of lua).
> If you were to do a similar thing for tonumber(), it would never get
> used by the Lua internals. Attached is a two-line patch to lbaselib.c
> that makes tonumber() behave just like tostring(), honoring a __tonumber
> metamethod (without the optional numeric base).
Thank you. And this is exactly what I am missing from the mainstream
lua. This small patch would be really helpful for some class of objects.