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
context.
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.