lua-users home
lua-l archive

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



> You're right.  I'm trying to write a class structure, and want to have
> functions that are callable from the class description rather than the
> instance.
> 
> But I just realized that Lua doesn't have to keep track of this
> information
> after compile so there's nothing to look for.

That's because it's not really a language feature but a syntactic
"sugar", so that's where the support ends. People often bitch in Python
that the explicit declaration of "self" is an annoyance, but it does
make the code clearer when methods in self are called, as you must use
self.method(), i.e. you know which scope you are calling. In C++ "this"
is always defined regardless of calling convention or declaration style.
Lua is in an awkward spot somewhere between. Personally I think its
better to explicitly declare self in your function definition ('.'
syntax) and only use the ':' syntax for calling.

Nick