[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lua-l
Subject:    Re: require+localizing=frustrating (was Re: Idea for a new kind of require)
From:       Patrick Donnelly <batrick () batbytes ! com>
Date:       2012-08-29 17:36:22
Message-ID: CACh33FopfV=gsS_zo+q02mMSyEcXc=4nVY7goOQFXd-C5MRv8g () mail ! gmail ! com
[Download RAW message or body]

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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic