[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Running lua code as as a single coroutine without creating lua thread
- From: Dmitry Marakasov <amdmi3@...>
- Date: Thu, 2 Feb 2012 21:33:32 +0400
* Patrick Donnelly (firstname.lastname@example.org) wrote:
> > I want lua code to be running as a single coroutine. For example,
> > imagine C/C++ GUI application with logic written in lua. GUI event
> > loop runs in C/C++, and lua code needs to drop back to it when it
> > needs input from the user (it can't get user input by calling C/C++
> > function, as this would not resume event loop). I'm trying to use a
> > single lua coroutine for it, but I'm confused about whether I can
> > call lua_resume on a lua_State returned by lua_open, not lua_newthread,
> > cause lua_resume documentation says "To start a coroutine, you first
> > create a new thread".
> It sounds like a bad idea to use the main thread for lua_resume for
> one simple reason: what happens in the event of an error? The main
> thread is "dead" and no longer can be resumed or used (or at least,
> this is undefined in the manual).
Why would I want to resume erroneous code? All I need in case of
error is to get some debug info, and that's pretty documented -
error string is on the stack, and stack trace is also possible to
> Better to use a dedicated thread created using lua_newthread I think...
I prefer to not spawn entities I do not need.
However, out of curiocity: should/may lua_State got from lua_newthread
be disposed in any way (lua_close) after it finishes? Yields? Gets an
Dmitry Marakasov . 55B5 0596 FF1E 8D84 5F56 9510 D35A 80DD F9D2 F77D
email@example.com ..: jabber: firstname.lastname@example.org http://www.amdmi3.ru