lua-users home
lua-l archive

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


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:

local f = c.f

function x (s)

	`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

_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!