[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Colon Operator: Superfluous Syntax?
- From: Mike Pall <mikelu-0703@...>
- Date: Thu, 15 Mar 2007 13:21:04 +0100
Hi,
Brian Hagerty wrote:
> So the information about "who called this function/method" is
> already available in the call frame (and already available in
> Lua's function call implementation).
It's not. At least not in general. Say foo is a global variable,
then foo.method() translates to GETGLOBAL + GETTABLE + CALL.
GETTABLE happily reuses the stack slot where GETGLOBAL put the
object in question. There's no way to retrieve it from the
caller's frame because it's simply no longer on the stack.
Don't even think about some bytecode acrobatics to reconstruct
it. There are cases where the object is computed, e.g.
foo(bar).method(). It might even have been garbage collected
already (due to side-effects of argument evaluation).
The only way to get some kind of implicit "self" inside a method
call is to either create bound methods or to implicitly pass it
in the caller (when available).
The first variant is used by Python and needs one heap-allocation
per method-call. Yay!
The second variant is used by Javascript and results in an
incredible mess. The key phrase here is: "when available". Look
at all those endless discussions about when "this" is available
and when not. Surely in the top 10 of Javascript shortcomings.
Please don't recreate the mis-features of other languages in Lua.
The colon operator has a valid rationale. Semantics are more
important than syntax.
Bye,
Mike