[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Running lua code as as a single coroutine without creating lua thread
- From: Patrick Donnelly <batrick@...>
- Date: Thu, 2 Feb 2012 11:47:47 -0500
On Wed, Feb 1, 2012 at 3:04 PM, Dmitry Marakasov <amdmi3@amdmi3.ru> wrote:
> Hi!
>
> 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).
Better to use a dedicated thread created using lua_newthread I think...
--
- Patrick Donnelly