[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: tonumber(), toboolean()???
- From: Chris Marrin <chris@...>
- Date: Tue, 21 Feb 2006 11:07:10 -0800
Lisa Parratt wrote:
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
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.
Hmmm. Why are they any different than tostring()? It seems like they
could be implemented outside the Lua runtime entirely and just added to
the global table (or replace the current one in the case of 'tonumber').
chris marrin ,""$,
firstname.lastname@example.org b` $ ,,.
mP b' , 1$'
,.` ,b` ,` :$$'
,|` mP ,` ,mm
,b" b" ,` ,mm m$$ ,m ,`P$$
m$` ,b` .` ,mm ,'|$P ,|"1$` ,b$P ,` :$1
b$` ,$: :,`` |$$ ,` $$` ,|` ,$$,,`"$$ .` :$|
b$| _m$`,:` :$1 ,` ,$Pm|` ` :$$,..;"' |$:
P$b, _;b$$b$1" |$$ ,` ,$$" ``' $$
```"```'" `"` `""` ""` ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'