[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Merging libraries' main loops
- From: Daurnimator <quae@...>
- Date: Tue, 15 Nov 2011 03:25:46 +1100
On 15 November 2011 03:05, Stefan Reich
> Here's a general question. Many Lua libraries define their own "master
> loop" that waits for events and processes them.
> Verse does this, IupLua does it, Copas does it. And I'm sure many
> others do it too.
> Question is: If I need two of these libraries at once, how do I
> combine their loops?
> There should be a general solution for this IMHO.
> The underlying question is, what events do the libraries wait on. If
> it's all socket select, it should be combinable quite easy. If it's
> something else, well... I don't know.
> Concrete example:
> I want to use both IupLua and Verse. How do I do it?
> Verse has a step() function and IupLua has timers, so I could call the
> Verse step function in an IupLua timer for a first approximation. Not
> optimal, timing-wise, probably, but it's a start.
> Any thoughts...?
Nearly every library with a loop function will also have a step() function
==> the loop function will just call step with an appropriate sleep inside.
To put together multiple libraries; just call their step functions.
Depending on how often you need to call it: you may end up with while
true do a.step(); b.step(); c.step() end
or you might end up with something more complicated that involved
waits or some other notification/event system.