[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: __colon
- From: Eduardo Ochs <eduardoochs@...>
- Date: Fri, 2 May 2014 16:41:16 -0300
On Fri, May 2, 2014 at 4:18 PM, Thomas Jericke <tjericke@indel.ch> wrote:
>> From: "Eduardo Ochs" <eduardoochs@gmail.com>
>> To: "Lua mailing list" <lua-l@lists.lua.org>
>> Date: 01-05-2014 23:07
>> Subject: __colon
>>
>> Wouldn't it be much more Lua-ish to just create a new metamethod for
>> that? Here's how it would work. The current behavior of "a:b(c)" would
>> not be changed at all, and in all situations where "a:b" currently
>> raises a syntax error - including "(a:b)(c)" - Lua would instead
>> generate code that would look for a metamethod "__colon" in the
>> metatable of a;
>
> And how would you do that? I don't see a fast solution to generate
> such code without introducing a new opcode. I don't think it's
> worth to have an additional opcode that is only used for triggering
> a metamethod.
You are right - I was thinking of a small patch to the parser, plus
a small patch to the VM that would add a new opcode. Adding new
opcodes is bad, but anything that would slow down existing code
is FAR worse - that's why I thought that the opcode trick was ok...
>> when that metamethod is found, the result of "a:b"
>> would be this,
>>
>> getmetatable(a).__colon("b")
>
> You probably mean: getmetatable(a).__colon(a, "b")
Yep - thanks =).
Cheers,
Eduardo Ochs