lua-users home
lua-l archive

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


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.

- Spencer