lua-users home
lua-l archive

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

Mark Tomczak <mtomczak <at>> writes:

> Greetings all!
> We're considering a modification to the version of Lua embedded in our game 
engine that would allow for this construct (which is currently a syntax error 
in Lua):
> CallbackManager.postMyCallback(myInstance:instanceMethod)
> Under the present language rules, myInstance:instanceMethod is an error (as 
I understand it) because the colon notation is only valid in the context of 
function calls and function declarations, but is not valid in the context of 
specifying a function value. Currently, we can accomplish this goal by instead 
making the statement "CallbackManager.postMyCallback(function () 
myInstance:instanceMethod() end)", but that seems to be a great deal more 
typing than should be necessary.
> I picked the IRC channel's collective brain on this issue, and we discussed 
the performance impact aspects of this design. But I also wanted to ask the 
mailing-list community: is there any syntactical reason that I would want to 
avoid allowing myInstance:instanceMethod to become a valid construct outside 
of a function declaration (as, for instance, a shorthand alias for 
constructing the closure as I described)? I'm nervous about getting halfway 
down the road of trying out this modification and then running headlong into a 
language ambiguity.
> Thank you for the input!
> -Mark

Have you considred doing something like:

CallbackManager.postMyCallback(myInstance, 'instanceMethod')