lua-users home
lua-l archive

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


On Sun, Mar 5, 2017 at 7:21 PM, Dirk Laurie <> wrote:
> 2017-03-05 19:51 GMT+02:00 Francisco Olarte <>:
>> I'm used to languages which separate 'methods' and data, like C++ (
> I do the following:
> 1. Only data goes in the object table itself.

I more or less do that. Sometimes I put a function, but it is treated
as data ( not called in object like fashion, and normally used to be
passed around, like a comparator )

> 2. Methods go into the __index metamethod. No harm in tables
> having their own metatable.

mmm, I use a table for __index, but I assume that is a
typo/oversight/you call all slots metamethods. Anyway, this is what I
do but it does not stop me from periodically keying
'leg.placecall(ani, dnis)' and having it happily blow up in the test
phase when it calls the leg userdata __index[placecall] slot with a
string as self.

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

That maybe useful for me, as I could grep for '\w+\._\w+\(' to spot
errors, but it's tedious ( specially on spanish keyboards where _ is
shifted and just next to the right shift key ). Could give it a try.
But I find hungarian styles ugly ( although this is a light one ).

I really prefer strictly typed languages for the kind of things I do.
I tend to code really complex chunks which, when done in say, C++ ,
get lots of compile-time errors which I can easily fix. But in my
present usage, lua+luacheck, you only got that if you abstain from
using objects, as the table-lookup step masks every typo. I've been
looking for something which could give me compilation, but found
nothing I like so far.

Francisco Olarte.