lua-users home
lua-l archive

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


On Tue, Oct 18, 2011 at 19:48, Tang Daogang <daogangtang@gmail.com> wrote:
>
>
> On Wed, Oct 19, 2011 at 8:33 AM, Philipp Janda <siffiejoe@gmx.net> wrote:
>>
>> On 18.10.2011 05:53, Tang Daogang wrote:
>>>
>>> On Tue, Oct 18, 2011 at 11:04 AM, Norbert
>>> Kiesel<nkiesel@tbdnetworks.com>wrote:
>>>
>>> ;) I am sorry, Bamboo relies on lglib
>>> (https://github.com/daogangtang/lglib),
>>> in which I override the __add method with ..
>>>
>>
>> Not a good idea if your strings look like numbers:
>>
>> $ cat > adds.lua
>> local mt = getmetatable( "" )
>> mt.__add = function( a, b )
>>  return a .. b
>> end
>> print( "1" + "2" )
>> ^D
>>
>> $ lua adds.lua
>> 3
>>
>> Lua tries to convert arguments of '+' to numbers and apply numeric
>> addition *before* metamethods are involved.
>>
> That is true. I think this is lua's flaw, thanks for your mention, let me
> think how to treat this case.
>
>>
>> Philipp
>>
>>
>
>
>
> --
> Nothing is impossible.
>
>

This is by design. Metamethods are fallbacks, not overrides.

-- 
Sent from my toaster.