lua-users home
lua-l archive

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

My understanding is that lua_close() will automatically happen
when the script finishes running.  In that case am I forbidden
from running it explicitly after script completion?  As I see it,
lua_open() creates a context using dynamically-allocated
memory and lua_close() frees that memory again, so any
pointer which the application keeps to its lua_State
after the script has run is now pointing at free memory.
The manual is misleading on that matter, implying (to me)
that you can lua_close() a state if you like but you
generally do not need to, when in truth you must NOT lua_close()
a lua_State after running a script to completion with that

No the lua free the lua_state only when you call lua_close on it or when the app finish, so you can use it for all evaluation you want :

My final questions are hopefully just asking for clarification to the lua5 manual, really. The manual
says 'If you have a C library that offers multi-threading,
then Lua can cooperate with it to implement the equivalent
facility in Lua.  Also, Lua implements its own coroutine
system on top of threads'.

Well, this surprises me a bit because my understanding of
coroutines is something like 'threadless threads', just
a really convenient way of managing state-machines with
the dirtiness hidden away, but essentially still very much
single-threaded in reality.

This would be academic except that experience has made me
afraid of system-thread-using libraries.  I'm curious
as to whether lua's coroutines really require threads as
the manual implies; it looks like my lua500 build is not
linked to any thread libraries but the tests which use
coroutine.yield() still work fine.

The lua coroutine don't use any thread lib, the manual would say that you could have a real multi thread system in lua if you provide an external multi thread lib and you can use an independent implementation in lua of corountine, so if you don't have lib is like if you have only one thread and you run coroutine on it.

Thomas Lavergne                       "Le vrai rêveur est celui qui rêve
                                       de l'impossible."  (Elsa Triolet)    ICQ:#137121910