[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Clean Lua
- From: Miles Bader <miles@...>
- Date: Wed, 30 Nov 2011 10:40:17 +0900
David Manura <dm.lua@math2.org> writes:
>>> local env; env = setmetatable({
>>> import = function(name, value) env[name] = value end
>>> }, {__index = _G})
>>
>> 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`.
Sure, that's a problem with the 5.1 version. I'd consider acceptable
in this case to say "so don't do that!", but your implementation might
also be a good way to avoid such problems.
However, I'm more interested in what people think of the tradeoff
between the two suggested forms in 5.2:
import (_ENV, "blah", ...)
vs.
import ("blah", ...)
with "magic" setting of the environment by the file-loading machinery
Is slight "ugliness" of the former justified by the additional clarity
of being explicit and possibly a bit more robust/flexible?
-Miles
--
Absurdity, n. A statement or belief manifestly inconsistent with one's own
opinion.