lua-users home
lua-l archive

Re: retrieve top-level lua_State?

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


The memory of a coroutine's lua_State can get garbage collected and
freed automatically, whereas the top-level state's memory will not get
freed unless specifically asked. This can be a problem if a
coroutine's code calls a C function, which then records the pointer of
the passed-in lua_State. If the coroutine ends and its state gets
freed, the C-side code may end up crashing if it tries to use that
lua_State. One fix to this is to use the top-level state.
One portable way to deal with this is to store a pointer to the
top-level state as a userdata in the global environment. It's not the
fastest solution, however it may be fast enough depending on what
you're writing.
-- David Ludwig
On Sat, Jun 6, 2009 at 4:02 AM, Florian Weimer<fw@deneb.enyo.de> wrote:
> * Graham Wakefield:
>
>> Given the other responses on that thread, is there any chance this
>> will make it into Lua 5.1.5?
>
> I don't quite understand the need.  How is the top-level state
> different from any other state?
>

AltStyle によって変換されたページ (->オリジナル) /