[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: a case for multiple environments - expressing modules more naturally
- From: Miles Bader <miles@...>
- Date: Tue, 10 Aug 2010 13:46:14 +0900
Shawn Fox <shawnkfox@gmail.com> writes:
> parser = require "lpeg"
>
> The problem I have here is that I just don't believe that is the normal
> thing to do.
"Old" packages (5.0?) don't do that, but I think it's been recommended
practice for quite a while. Moreover, it's clearer and simpler than
adding implicit entries to the global table.
+1 from me for the "new way."
> Although I may not be understanding all the details of how _ENV works...
You don't have to use _ENV if you don't want to, of course (that's one
nice thing about using standard mechanisms rather than "magic" ones).
For instance, I find the following extremely readable:
mymod.lua;
local mymod = {}
function mymod.fun1 () end
function mymod.fun2 () end
return mymod
-Miles
--
Laughter, n. An interior convulsion, producing a distortion of the features
and accompanied by inarticulate noises. It is infectious and, though
intermittent, incurable.