lua-users home
lua-l archive

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


2017-03-05 19:51 GMT+02:00 Francisco Olarte <folarte@peoplecall.com>:

> I'm used to languages which separate 'methods' and data, like C++ (
> which, both being statically typed can do the proper thing with the
> dot depending on the decl ) or even perl ( where you do
> $obj->method(...) or $obj->{function}->(...) ), and it bites me every
> single day. I alleviate it by grepping periodically on the source (
> for '\w+\.\w+\(' ) and stashing the rarely used function call in
> locals ( obj:method(), but local f=obj.func; f(...) ), but is one of
> the major pains I encounter when doing moderately complex code in lua.

I do the following:

1. Only data goes in the object table itself.
2. Methods go into the __index metamethod. No harm in tables
having their own metatable.

Another trick is to have a habit to start method names with a single
underscore, but personally I don't always do that.