[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Clean Lua
- From: David Manura <dm.lua@...>
- Date: Tue, 29 Nov 2011 20:19:24 -0500
On Tue, Nov 29, 2011 at 3:47 AM, Miles Bader <miles@gnu.org> wrote:
> David Manura <dm.lua@math2.org> writes:
>> -- load.lua
>> local env; env = setmetatable({
>> import = function(name, value) env[name] = value end
>> }, {__index = _G})
>> assert(loadfile('foo.lua', nil, env))()
>
> Hmmm, that would work, but would require one to keep tight control on
> file loading [...]
It can even be preferable. Consider for instance trying to pass
`import` as a callback function like `pcall(import, ...)`. Your
original code probably would fail there because it would attempt to
write into the C environment of `pcall`. There was once a Lua bug
similar to that [1].
[1] http://www.lua.org/bugs.html#5.1.3-11 `pcall(module, "xuxu")`