lua-users home
lua-l archive

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


On Sun, 16 Jan 2005 12:17:04 -0500
Jay Carlson <nop@nop.com> wrote:

> skaller wrote:
> > On Mon, 2005-01-17 at 04:07, André de Leiradella wrote:
> > 
> > 
> >>The thing the bothers me most is how to call inherited methods.
> > 
> > 
> > An object is nothing more than a table of closures. 
> > OO is just a minor subset of functional programming.
> > 
> > Inheritance is no problem, just modify the table
> > in the derived class .. which is just a function
> > that calls the base function first to
> > make the initial table.
> > 
> > function base(x) 
> >   return { 
> >     ["meth1"] = function () return x end;
> >     ["meth2"] = function () return 2 end
> >   }
> > end
> 
> [...]
> 
> > Note -- no 'self' argument is needed,
> > the private variables of a class can be
> > refered to directly in the method without
> > any 'self'. Also no metatables or environments
> > (whatever they are) are needed. 
> > 
> > All you need is lexically scoped functions and tables,
> > Lua already has both.
> 
> How do you refer to object slots defined by parents?

Hmm... forgive my ignorance; last night I suspected you could get at
a function's locals and upvalues by using getfenv().  Apparently not. 

You can get to them through the debug interface... that seems a far cry
from 'elegant' though :)

If it wasn't called the 'debug' interface, and you could get at them by
name, it wouldn't feel so bad...

> How do you do super dispatch?

This seems possible (unless I misread what you mean):

Subclass.new = function()
    local method = Superclass.new()
    local super_foo = method.foo
    method.foo = function(bar)
        print("Look, I'm adding stuff to foo!")
        super_foo(bar)
    end
    return method
end

> Jay
> 

-Chris