lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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