lua-users home
lua-l archive

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

My two cents in this discussion is that I get your point that a shorter syntax nicer to write.
However, it makes it less readable for the future programmer.
I don't think Lua is too verbose so it is a real annoyance, it has quite the right balance, and I wouldn't like to see readability damaged. 

2016-04-19 14:13 GMT+02:00 John Hind <>:
> | Message: 6
> | Date: Tue, 19 Apr 2016 12:58:31 +0200
> | From: Ulrich Schmidt <>
> |
> | I like programming using OOP and it works quite well in Lua.
> | I don't miss anything related in lua, OK.
> |
> | But sometimes when coding class methods and entering class names again
> | and again, i feel a wish comes up:
> |
> | Would it be possible to implement a shortcut usable inside class
> | so i can write
> |    :method instead classname:method
> | and
> |    .field instead classname.field.
> |
> | ?
> |
> | Ulrich.

Do you mean simply that:

':method'  would be a syntax shortcut for 'self:method'


'.field' would be a syntax shortcut for 'self.field'


Beyond that you are opening a (very familiar) can of worms. Lua does not
have the concept of 'class' and this concept can be implemented in many
different ways, so 'classname' could be a table or a userdata or in my
personal favourite style, a function closure. So there is no determinate
lexical context for a class - it all depends how you want to implement it.

Etiene Dalcol

Software Engineering student at ENSTA Bretagne and PUC-Rio
Sailor Developer
Lua Ladies Founder