lua-users home
lua-l archive

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


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