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
current
> > global table and replace it with your class object.  That is, when the
user
> > calls obj:fullName() it's really first handled by a wrapper that
switches
> > 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)
        globals(oldtable)
        return val
    end

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...

-John