lua-users home
lua-l archive

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


 
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
threads.

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] 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 <nick@gammon.com.au> 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
>
 








DISCLAIMER 
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 postmaster@creative-assembly.co.uk 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.