[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Globals in 5.0 Alpha
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 19 Aug 2002 11:29:10 -0300
> Also, since only a function scope may have its globals table
> manipulated, a wrapping function must exist to create the namespace.
Remember that every chunk is a function, and therefore you can change
its namespace; you don't need a wrapping function. As lhf pointed out,
it is very easy in Lua to change the namespace of the calling function
(see documentation for `setglobals'). So, you can start your chunk
with something like
namespace "my_name"
so that the `namespace' function will change the global table of the
calling function (the chunk, in that case).
As an alternative option, you can change the namespace from the outside,
when you load a "module":
local f = loadfile(filename)
local new_namespace = {...}
setglobals(f, new_namespace)
f() -- run the chunk
-- Roberto