lua-users home
lua-l archive

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



-----Original Message----- 
> 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.

> 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")
--
Thomas