[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Packaging and importing
- From: Tomas <tomas@...>
- Date: Sun, 14 Aug 2005 21:05:26 -0300 (BRT)
Hi,
Thanks for the help so far. My big issues still have to do with isolating
namespaces. For instance, what about the problem I mention above? Are
modules required by "b" isolated from those required in "a", like they are
in Python?
No. All modules are available globally. If both "a" and "b" require"c",
both will share the same module. That said, Lua is powerful enough for
you to override this behavior. I believe VEnv, used with CGILua, does that.
Once again, Lua gives you the power. If you need a sandbox, it can be done.
What I have to add to Diego's explanation is that a module
that needs a certain global could store it in a local not only to gain
some speed, but also to guarantee that this global will be exactly the
same during its execution. For example:
require"c"
local f = c.f
module"a"
function x (s)
f(s)
c.g(s)
end
`f' is the local copy of `c.f', made after the require"c"
(this required library could be an already loaded library, as Diego
told); `c.g' will be _M.c.g (_M is the module's global table created
by `module()'), but as `c' is inherited from the original globals table,
it will be _M._G.c.g, which could be easily changed outside the library.
Also, has anyone made a proposal for how you can promote all the members of
"a" into the namespace of the module that requires "a"?
Why don't you inherit the symbols from "a" with something
like:
require"a"
_M = {}
setmetatable (_M, { __index = a }) -- inherit from "a"
setfenv (1, _M) -- new environment (global table)
If "a" inherits from the global table you'll get all global
through it!
Tomas