lua-users home
lua-l archive

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


On 5/11/2012 6:40 AM, Thomas Harning Jr. wrote:
> When working on coroutines and callbacks in the past, I found it best
> to store the calling Lua state before entering whatever outside loop
> was about to occur.


I just ended up with the same pattern, only using a stack.

Whenever I call into Lua from C, I push that state onto the "L" stack. If Lua calls C, and THAT C function calls back into a different Lua state (can happen), then I push another "L" onto the stack.

I have at least two distinct Lua code environments in my library, and it feels cleaner to me to have a completely separate lua_State for each environment. And it's possible (likely, even) for code from one environment to trigger code that uses the other one.

The global "L" stack doesn't get used in many situations, though, and possibly not at all in any but my primary (scripting) environment. So it's likely overkill. But it makes me happy. :)

Tim