lua-users home
lua-l archive

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

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

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()

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:
> []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