lua-users home
lua-l archive

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


> | Message: 6
> | Date: Tue, 19 Apr 2016 12:58:31 +0200
> | From: Ulrich Schmidt <u.sch.zw@gmx.de>
> | 
> | 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
methods,
> | 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'

And

'.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.