lua-users home
lua-l archive

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

I would use '__index' only and leave '__newindex' out. In addition, I would create the entry "global" in the thread's proxy table and set it to the 'master' global table (the one from the main state). This way new variables created at global level would go into the private thread' global/proxy table. In order to add anything to 'master' global table one would have to say <global.x = blah> as <x = blah> would add 'x' to the thread's proxy. On the other hand, accessing global values would use 'master' global table if not found in the thread's global per previous poster's suggestion. 


-----Original Message-----
From: Peter Loveday []
Sent: Wednesday, October 08, 2003 9:10 PM
To: Lua list
Subject: Re: Thread woes

> When you call 'lua_newthread' the object given back to you automatically
> has the same global environment table as did the state it was created
> from. So right now if I get the environment table through 'getfenv' I
> get the global table that the master state currently has. This is more
> or less what I want here, one large global table that has all my
> libraries loaded into and is seen by every thread. You can change this
> table, and if I set a new table for a thread through 'setfenv' the
> thread can no longer see all of the library functions I loaded into the
> states global table unless I load them into the new environment table as
> well. But If I am going to do that I might as well go back to giving
> everything its own state which was too heavy to begin with (memory
> wise).

You can create a proxy table as the global environment for each thread;
simply create a table, and set its metatable __index/__newindex to point to
the original globals.  You can set 'thread local' values into it either
before setting its metatable, or using rawset.

Love, Light and Peace,
- Peter Loveday
Director of Development, eyeon Software