[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: require+localizing=frustrating (was Re: Idea for a new kind of require)
- From: Patrick Donnelly <batrick@...>
- Date: Wed, 29 Aug 2012 13:36:22 -0400
On Tue, Aug 28, 2012 at 3:49 PM, Sam Roberts <vieuxtech@gmail.com> wrote:
> On Tue, Aug 28, 2012 at 12:40 PM, Patrick Donnelly <batrick@batbytes.com> wrote:
>> Because the library is stored in a global, all subsequent access would
>> be correct. This quickly deteriorates into a situation where the
>> script writer depends on a library which depends on another library
>> that the script uses incidentally but forgets to require:
>
> Did you consider loading every script into its own environment, so its
> "globals" go into a table just for it, rather than _G?
We already do this for threaded scripts to eliminate the problem for
global accesses. For libraries, you must use locals as there is only
one "instance" of the code.
> You'd have to modify require to understand this convention, but it
> would allow people to not do explicit local, and still get script
> isolation.
It's not a bad idea. We've only recently converted to using locals to
store the result of require; this was part of our conversion to Lua
5.2. Since the official idiom solved the problem, I didn't explore
other options.
--
- Patrick Donnelly
- References:
- Idea for a new kind of require, Rob Hoelz
- Re: Idea for a new kind of require, Duncan Cross
- Re: Idea for a new kind of require, Rob Hoelz
- Re: Idea for a new kind of require, Duncan Cross
- Re: Idea for a new kind of require, Rena
- Re: Idea for a new kind of require, Javier Guerra Giraldez
- Re: Idea for a new kind of require, Rob Hoelz
- Re: Idea for a new kind of require, Rob Hoelz
- Re: Idea for a new kind of require, Doug Currie
- require+localizing=frustrating (was Re: Idea for a new kind of require), Jay Carlson
- Re: require+localizing=frustrating (was Re: Idea for a new kind of require), Dirk Laurie
- Re: require+localizing=frustrating (was Re: Idea for a new kind of require), Patrick Donnelly
- Re: require+localizing=frustrating (was Re: Idea for a new kind of require), Sam Roberts