[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Number 2 String( LUA_NOCVTN2S ) and numbers and concat...
- From: Andrew Starks <andrew.starks@...>
- Date: Thu, 26 Mar 2015 16:42:17 -0500
On Thu, Mar 26, 2015 at 4:15 PM, Andrew Starks <andrew.starks@trms.com> wrote:
> In Penlight's `operator.lua` we see:
<snip>
>
> As I see it, concatenation works on strings. Its event method is
> available for abuse by userland metatables, or perhaps to format an
> object's string representation differently, by other value types, if
> they define it. Otherwise, the value is converted to a string and then
> concatenated.
>
> Now, I know that I'm talking out of both ends, not wanting coercion in
> one spot and wanting it in the other. The problem is that numbers
> don't have a metatable, unless you mess with debug.setmetatable. So
> making them concat correctly requires you to wrap it in `tostring`,
> whereas you wouldn't have to, if it were a table.
>
> Here, I that I wish that concat would use tostring on all non-string
> value types that do not have metamethods, instead of erroring. At the
> same time, dropping support for `__concat` would seem reasonable.
> -Andrew
Sorry to reply to my own post, but I'm not sure about this suggestion.
I'm thinking that the most consistent solution is pretty much the one
that I did and that if I could suggest any changes, it might only be
that this (or a similar/better/simpler) solution would be another flag
that could be defined, as a friendly complement to LUA_NOCVTN2S.
The main point is that this concatenation issue exposes the fact that
numbers were using magic and not metamethods for concatenation.
At the end of the day, I may just give up on LUA_NOCVTN2S and just
learn to let it go.... :)
-Andrew