lua-users home
lua-l archive

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

The : vs . calling convention in Lua does certainly bite you from time to 
time. But it is hard to see a way of changing it which does not seriously 
change the semantics of the language.

The problem is that <object.method> is a function. It might be a function 
which expects a "self" argument or not, but it is in any case a 
first-class object. So it is completely legitimate to do the following:

  function map_method(object, method, ...)
    local meth = object[method]
    for i = 1, args.n do
      meth(object, args[i])

There is no : whatsoever in the above example, but it is certainly 
expected that the method would be a "self"-style method.

Unfortunately, this opens the possibility of applying a method to a 
different object. Sometimes, of course, that is actually useful, as in the 
case of calling a method from a superclass:

  function MyWidget:handle_key(keycode)
    if keycode == META "b" then
      Super.handle_key(self, keycode)

Edgar Toernig, in his Sol, has an interesting approach, but it involves 
completely changing the semantics of :-style calls.

I don't really have an answer, but it is an interesting problem.