lua-users home
lua-l archive

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

Steve wrote:
> John Belmonte wrote:
> > 1) make a wrapper for your classes methods that would back up the
> > global table and replace it with your class object.  That is, when the
> > calls obj:fullName() it's really first handled by a wrapper that
> > the global table and then calls the actual fullName().
> It seems that the cost of this step would exceed the benefit of the
simpler syntax.
> Is there some way to avoid this problem?

I don't agree that it would be so bad.  One implementation is in the field
fullName you'd have a wrapper object whose "function" event is set to
something like:

    function wrapper(obj, ...)
        local oldtable = globals(obj.locals)
        local val = call(obj.realfunc, arg)
        return val

This function could be implemented from C.

The thing is, you can do much more with this than just eliminate the self's
in your classes.  You could do a mean module system, closures, namespaces...