lua-users home
lua-l archive

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


What about accepting the ugly stuff if it comes inside parentheses,
like in

    function (mylib.MyClass):method() ... end

contrasted to the problematic

    function mylib.MyClass:method() ... end

?

This isn't accepted right now, but I think that allowing it would be a
simple (and reasonably elegant) change and wouldn't break anything or
create any ambiguities.

Cheers,
  Eduardo Ochs
  http://angg.twu.net/
  http://www.mat.puc-rio.br/
  edrx@inx.com.br


John Belmonte wrote:
> I don't need the full sugar (the embedded function call), just one
> more teaspoon to cover a very common case:
>
>     function mylib.MyClass:method() ... end
>
> Let's try the "accepted syntax":
>
>     -- oops, you can't do this!
>     mylib.MyClass:method = function() ... end
>
> So now we're down to:
>
>     mylib.MyClass.method = function(self) end
>
> Which makes it very hard to identify class members functions in your
> code, even with syntax highlighting.  And you've lost the method
> definition sugar.
>
> The "temp variable" workaround is the worst looking of all, and
> defeats trying to keep everything inside mylib:
>
>     local temp = mylib.MyClass
>     function temp:method() ... end
>
> Please consider Edgar's function definition extension for Lua.