lua-users home
lua-l archive

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



On 11 Aug 2006, at 15:13, D Burgess wrote:

Sorry I was too brief.

All driven by C.

The lua code is initially loaded with luaL_loadbuffer() and
this chunk(function) is placed in a table.

A thread is created with lua_newthread and this thread
gets its own environment which metatables back to the
universe environment.

The function(chunk) is pushed into this thread and its
environment is set (with lua_setfenv() to the environment of
the thread  into that it is pushed.

With the function on the top of the stack we then can
use  lua_resume()  to invoke the function.

The function environment which is the same as the thread
environment methinks is not shared between threads. Even
if I push the same function into the different thread stacks,
I am of the view that I get differnt functions with different
function environments.

Doesn't sound right to me. If I push the same function onto two different threads then each thread still references the one function and that one function has just one environment.


The original problem that I observed was that after the
lua_resume() completes, if you attempt to set the
environment of this function (which happens to still
be on thread stack()) then unlike the original setfenv()
which was constrained to the thread, this second
lua_setfenv() appears to set the environment of each of
the functions in each of the other threads (which are in
a yielded state) to nil.

Isn't this explained by there only being one function that is shared by all your threads?

drj