[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: "Require" in a sandboxed environment
- From: "Tom Miles" <Tom@...>
- Date: Thu, 9 Aug 2007 09:33:03 +0100
I create multiple threads using lua_newthread(), all hanging off the
same state, which behaves thusly (from 5.1 manual) : "Creates a new
thread, pushes it on the stack, and returns a pointer to a lua_State
that represents this new thread. The new state returned by this function
shares with the original state all global objects (such as tables), but
has an independent execution stack."
I would therefore expect all packages to be shared amongst all the
[mailto:email@example.com] On Behalf Of Duncan Cross
Sent: 09 August 2007 09:19
To: Lua list
Subject: Re: "Require" in a sandboxed environment
It looked to me like it uses multiple Lua threads within the same single
main state, not multiple main states - shouldn't they share the registry
and therefore loaded packages?
On 8/9/07, Nick Gammon <firstname.lastname@example.org> wrote:
> On 02/08/2007, at 5:48 PM, Tom Miles wrote:
> > We know that the environment 1 code is called before environment 2,
> > yet the results are the ouput is:
> > 1
> > nil
> From what I can see of your code you are making multiple Lua states.
> When you "require" something it is like a '#include <file>' in C, you
> get a copy of the code, not a shared state. Thus, the variables in
> Utilities.lua are independent from one state to the next. Of course,
> if you "require" something twice in a single Lua state then its
> variables are shared, because it is being loaded into the same state.
> - Nick
This email is sent by The Creative Assembly Limited company No. 03425917, registered in England &Wales registered office 27 Great West Road, Middlesex, TW8 9BW, England. The contents of this e-mail and any attachments are confidential to the intended recipient and may also be legally privileged. Unless you are the named addressee (or authorised to receive for the addressee) of this email you may not copy, disclose or distribute it to anyone else. If you have received this email in error, please notify us immediately by e-mail on email@example.com and then delete the email and any copies. The Creative Assembly Limited have made all reasonable efforts to ensure that this e-mail and any attached documents or software are free from software viruses, but it is the recipient's responsibility to confirm this.