[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: function kidnapping
- From: "John Belmonte" <jvb@...>
- Date: Mon, 8 May 2000 21:40:21 +0900
tomas@ccpa.puc-rio.br wrote:
> > -- Assuming tag methods in place to allow swapping of global table
via
> > -- a function "setglobaltable".
> > function wrapper(func, ...)
> > local oldtable = setglobaltable(t)
> > local val = call(func, arg)
> > setglobaltable(oldtable)
> > return val
> > end
>
> With this wrapper, when you swap the global table you'll loose
> (while executing the function, of course) all global functions, like
> print, gsub, write etc. I think it would be better not to change the
> global environment but to check if the global exists. If it doesn't,
> so try the local value.
Of course that depends on how you implement the tagmethods ("getglobal",
etc). Probably you would have them search in t first, and if it isn't there
use rawgetglobal(). Or maybe when the namespace system is initialized copy
all "system globals" to a special namespace called std (I'm thinking of ANSI
C++ with the "std" namespace enabled). Then all accesses to system globals
must be explicit, for example std.print(). (This will break if system
functions need to call eachother.) A "using" could be implemented to open
up namespaces. There are a lot of options.
Using the name setglobaltable() was probably misleading.... but I said
"roughly" ;)
-John