lua-users home
lua-l archive

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


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?