lua-users home
lua-l archive

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


On Sep 1, 2013, at 12:52 AM, Thijs Schreijer <thijs@thijsschreijer.nl> wrote:

> 
> 
> Not an answer to your question, merely a remark on states. Depending on whether you need the pointer to a State or to a thread/coroutine inside a state your solutions may not work properly. The lua_State you get could point to a coroutine, which might die anytime after you've stored it.
> On 5.2 you might use the LUA_RIDX_MAINTHREAD [1] index to get the mainthread for the state. But that will also cost you one registry table lookup.
> 
> Thijs
> 
> [1] http://www.lua.org/manual/5.2/manual.html#4.5 
> 

Very good point, and one I'd not fully considered. I wonder about the "custom allocator" trick; it would seem to me that additional coroutine Lua states should all share the same allocator, in which case lua_getallocf() should always work regardless of the Lua_State passed to the C function; I've not had time to test this yet; the docs are silent on this.

--Tim