lua-users home
lua-l archive

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


On Wednesday 27 August 2003 06:13, D Burgess wrote:
> In lua5
>
> st,a,b = pcall(object:func, parameter)
>
> does not work
>
> while
>
> st,a,b = pcall(object.func, object, parameter)
>
> is required.
>
> Is this a fault or by design?

It is by design, although whether that design is flawed is a matter of 
opinion. The : notation is merely a syntactic sugar for method calls. It 
doesn't have more general semantics. You're wanting it to behave like:

function colon(table, methodname)
    return function(...)
        return table[methodname](table, unpack(arg))
    end
end

And it just doesn't. All it does is hide the 'self' parameter. I'm guessing 
the authors just didn't want to introduce the overhead of a closure? Maybe 
we'll see an optimiser in a future installment of Lua so it becomes 
practical? Having separate 'index' and 'method' metamethods would be good 
too.

 -- Jamie Webb

Heisenberg was here. I think.