lua-users home
lua-l archive

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


on 3/9/07 6:06 AM, Spencer Schumann at gauchopuro@gmail.com wrote:

>> as long as any object field can be accessed like a table member and any
>> method
>> takes the object as the first parameter, you can readily forget how
>> the 'object' was created and how it's 'class' was defined.
> 
> Even though the basics of Lua's object system is mostly standardized,
> there are some important details that are left out.  You mentioned
> inheritance, for one.  Furthermore, even the means of calling a method
> is not completely standardized: depending upon your object system of
> choice, you may or may not need to pass the object itself as the first
> parameter.  Syntactically, this means that you either have to use "."
> or ":" to call the method.  Perhaps I'm being a bit pedantic here, but
> this one has bitten me several times.  Most other languages have a
> single syntactic construct for calling methods.  C++ also has two,
> either "." or "->", depending upon whether a pointer to the object is
> being used, but the blow is softened there by static type checking -
> the compiler catches misuse of the two tokens.  In Lua, those kinds of
> errors do not show up until run time.
> 
> If all of your objects use one or the other syntax, it's not hard to
> remember which calling convention to use.  If, however, you're using
> several libraries within a piece of code that use different
> conventions, it can be difficult to keep the two straight.

I would say that the colon notation is the standard way to call Lua methods.
Periods are mostly used by people who just can't stand that bit of syntax.

The one problem I've found with colons is that using a period when you
should have used a colon (or vice-versa) will tend to generate rather
obscure errors. It would be nice if there were an easy way to test for this
mistake at least when running development versions.

Mark