lua-users home
lua-l archive

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


----- Original Message ----- 
From: "Michael T. Richter" <mtr1966@hotpop.com>
To: <lua@bazar2.conectiva.com.br>
Sent: Wednesday, June 18, 2003 7:15 AM
Subject: Stupid question about Lua threads/coroutines.


> OK, I've got a grip on coroutines from Lua-side (and like them VERY
much!).
> And I *think* I understand how to do pre-emptive threading from the C side
> using the Lua API.  But there's a feature of the Lua API I just don't
> understand that's interfering with total comprehension.
>
> At issue is lua_newthread().  In the description it states that it "pushes
> the thread on the stack and returns a pointer to a lua_State that
represents
> this new thread".  This strikes me as redundant given that the only use I
> can see for a "thread" pushed onto the stack is to later, somehow, use
> lua_tothread() to convert it into a lua_State that... represents said
> thread.  Further, there doesn't seem to be any way to push a thread onto a
> stack once you've taken it.  What role does this thread play, then?  Why
is
> it on the stack?  Is it legal to pop it, or will this bring the whole
> edifice crumbling down around me?


You can also save the "thread state" on the stack in a variable, table or
whatever, to access it later.