lua-users home
lua-l archive

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


> 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