[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Re[2]: about the next version
- From: "Peter Prade" <prade@...>
- Date: Wed, 17 Apr 2002 13:21:34 +0200
Hi,
how about beeing able to set more than one table:
globals in self, globals()
which means:
- on write access, self is used
- on read access, first self, then globals() is used.
i know i can setup something similar with tagmethods, but that would change
the first table for all accesses.
hmm, maybe set a proxy table like this:
function proxytable(t, t2)
local ret = {t, t2}
-- setup tag methods, so that indexing ret routes those accesses to the
included tables
return ret
end
then you can write:
function class_instance:method()
globals in proxytable(self, globals())
initialize() -- calls class_instance.initialize() (and not
class_instance:initialize(), doh)
print() -- calls globals().print()
end
but this will create a new proxytable every time the function is called...
would be hard to hardwire this into lua (without the gc littering)?
Peter Prade
Another thought:
:initialize() -- this could use the table that is set up as global table as
a first parameter
> -----Original Message-----
> From: owner-lua-l@tecgraf.puc-rio.br
> [mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of Luiz Henrique de
> Figueiredo
> Sent: Wednesday, April 17, 2002 12:16 PM
> To: Multiple recipients of list
> Subject: Re: Re[2]: about the next version
>
>
> >Oh! Big move for OOP-like programming style.
> >
> >function class_instance:method()
> > globals in self
> >
> > initialize()
> >end
>
> That was not the primary motivation for introducting "global",
> but it works.
> Just note that "globals in self" routes *all* undeclared
> variables to "self":
> you'd have to declare global functions and such if you use them.
> --lhf