lua-users home
lua-l archive

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


On Fri, Aug 22, 2003 at 12:24:10PM +0600, Antero Vipunen wrote:
> Hello Jules,
> 
> JB> But, as I described, it is quite possible to change the global
> JB> environment of each thread: why is that not adequate for your needs?
> 
> Because I also need global vars as well...

Well some solutions are:

a) If your global vars are 'by-reference' types (i.e. tables,
tolua-style userdata) then you can simply have them existing in both
threads' global environments. Any alterations to their fields will in
fact be referring to the same table.

b) If you need 'by-value' shared globals (strings, numbers) then you
need to use metatables. Basically you have a 'real' underlying globals
table, and each thread gets a separate proxy table.  Accesses to
undefined globals are set up to pass requests back to the underlying
globals table, attempts to create 'new' globals create them in the
proxy table.

Jules