lua-users home
lua-l archive

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


Although there's more than one way to skin the OOP
cat in Lua, it would be useful to have some conventions.

For example, consider a class browser.  Such code can't
even assume that the methods are stashed in the
object's metatable!  One solution is to expect class
systems to export some standard functions:

1)  _classes_defined
A user-defined iterator for finding all the classes defined
in the system.  (If it isn't defined, we can probably cope
by browsing the global environment recursively)

2) _base
Any table intended to be used as a class will export
a method _base, which may of course return nil.

3) _methods
Any class must define this iterator, which gives the
available methods; from there, the debug interface
could give us where they're physically defined.
(Whether this gives _all_ inherited methods, or just methods
defined by this class, is an interesting question.
I'd say this should be an option)

So no matter how one sets up one's object system,
such a convention would allow general tools 
to be built that don't require detailed knowledge
of the object system.

steve d.