lua-users home
lua-l archive

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


Thank's

But if I do 
myGlobals = globals()
myGlobals reference the globals table and all new objects are also added
to globals table.

I want to do this, to export in myGlobals only some objects and to do
some task like dofile or dostring with this new environnement and
finally to get some results and restore initial globals and then clear
myGlobals and all temporary objects. 

So I must clone globals at start time, to save a minimal environnement.
And so I can use a clone of
my minimal environnement every time I want to do task that create many
temporary objects.

Bye,



Diogo Vieira Andrade a écrit :
> 
> Hello,
> 
> On Tue, 20 Mar 2001, Jean Claude Morlier wrote:
> >
> > What's the usage of globals([table]) ?
> > In the example above I try to assign my own globals but this don't work.
> > I need to set for a time myGlobals and after restore initial globals.
> > May be I don't do this in a fine way.
> 
>   Your example didn't work because you didn't save enough
> information to lua work properly. It isn't enough to save
> 'print', 'dostring' and 'globals'. For example, how could
> lua traverse a table without function 'next'? (anybody,
> if I'm wrong, please correct me).
> 
>   In order to this work properly, you should save the hole
> context to your table 'myGlobals', and then do whatever you
> have to. (see the corrections in the code below).
> 
> > a = 1
> > b = 2
> >
> > function x(l)
> >   print('x Start')
> >   local c = 8
> >   l.f = function(v)    print('function f () v = ' .. v)  end
> >   l.c = c
> 
> -- you won't need to copy these 3 funtions
> >   l.print = print
> >   l.dostring = dostring
> >   l.globals = globals
> 
> >   l.print("before globals(l)")
> >   l.savglobals = globals()
> >   globals(l)
> >   f(a)
> >
> >   print("after  globals(l)")
> >   print('before dostring');
> >   dostring('print("in dostring"); f(a); f(b); f(c); ')
> >   globals(savglobals)
> >   print("x end")
> > end
> >
> > myGlobals = {}
> 
> -- copy hole context to myGlobals here
> myGlobals = globals()
> 
> > myGlobals.a = a
> > myGlobals.b = b
> > x(myGlobals)
> 
>   Hope I helped somehow...
> 
>   Cheers,
>   -- Diogo.

-- 


@+

Jean Claude Morlier
-------------------
Quetzal Informatique
morlier@quetzal.fr
tél  : 0557261110