lua-users home
lua-l archive

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

I seem to have got the idea that this was originally a Mark H
proposal, but he was just a supporter (by his own admission)

The idea is that 'obj:method' (without parenthesis) is sugar for the
closure  'function(...) return obj:method(...) end', so that you can
bind methods to a particular object (rather as how C++ Builder
considered as  '__closure' in its extensions to the language)

It isn't as ambiguous as one might think, in fact it resolves an ambiguity:

> s = 'hello'
> fn = s:find
>> (
stdin:2: ambiguous syntax (function call x new statement) near '('

(This is one of the few cases where newlines will mess with the Lua parser)

It definitely was considered in Rio. Luiz rules out another
overloading of obj:method on these grounds in [1], although Roberto
presents a simple Lua function to do this in [2] (and jokes that it
should work in other cities as well.)

And then froese comes back with a concrete proposal [3].

Any further thoughts about this rather useful construct?

steve d.