lua-users home
lua-l archive

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

On Sun, Jan 16, 2005 at 12:42:22AM -0500, Jay Carlson wrote:
> I've been pleasantly surprised that Lua seems to work well without a 
> mandated object system.  My initial fears were that this lack would lead 
> to just the problems you mention.

Indeed. When I first started with Lua, I wrote a simple object system
which sometimes didn't have a feature I wanted, so I had Great Plans
to build a C module implementing an object system on the scale of
CLOS, that would satisfy all my current and future needs. Fortunately,
I hadn't wasted too much time on it when I realised it was a bad idea.

The great thing about Lua is that you don't need a complex object
system in order to do whatever you want with objects. The language and
libraries define the meanings of the : and . operators, and as long as
you follow that convention, users will see a standard object system,
however it happens to be implemented in this case.

In my latest project, I'm using a few specialised 'kinds' of object.
Each kind is implemented as a single short function which creates a
blank class table ready to be populated with methods. Specialisation
means that none of the kinds are overburdened with features, and if
some radical new feature suddenly becomes appropriate, I can apply it
only where it's useful and avoid breaking anything. It doesn't matter
that I'm using several different object systems within the same
program because they all have the same conventional external
behaviour, and even stuff like inheriting between kinds works

If there were a standard object system, people would start depending
on its internals, and so other people would be forced to use that
system in order to remain compatible, even if it had a completely
inappropriate feature-set for the task.

-- Jamie Webb