lua-users home
lua-l archive

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


Hi,

Just wondering if any lua guru can suggest a way I might retrieve the top-level lua_State pointer in a module's C function.

Given that a lua_State * can be spawned from another with coroutine.create() or lua_newthread(L), it's not always guaranteed that the lua_State * pointer you receive in module functions is always the same, but the top-level state would always be. Even the lua_State * received in the luaopen_xxx call might not be the top level (e.g. require() was called in a coroutine.)

The reason is that I need a unique index with which to call back into distinct Lua universes, in a situation where several such universes may coexist (but not interact) in the same application, and (distinctly) load the same module. I would prefer not to defer this responsibility to the application itself or require modifications to Lua itself, as it would reduce the portability of the module in question.

I hope the question is clear. Any ideas?

Thanks