Lua Gems: Filters, Sources, Sinks and Pumps

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Lua Gems: Filters, Sources, Sinks and Pumps

Leo Razoumov
Hi List,
I ordered "Lua Gems" on Monday morning from Amazon.com using free
shipping (the slowest shipping option available in the US that costs
nothing). To my great surprise next day (on Tuesday) I found the book
on my door steps!

Now I am reading Diego Nehab's gem on "Filters, Sources, Sinks and Pumps".
To my surprise he does not mention coroutines. I think coroutines with
their "yield" and "resume" are great mechanism to implement filters
and filter chains. They provide an easy and natural way to maintain
filter context while processing chunks of data. Also coroutines all
but eliminate (or rather hide) need for "pumps".
Is there any specific reason they are left out of this gem??

--Leo--

Reply | Threaded
Open this post in threaded view
|

Re: Lua Gems: Filters, Sources, Sinks and Pumps

Diego Nehab-3
Hi,

Now I am reading Diego Nehab's gem on "Filters, Sources, Sinks and Pumps".
To my surprise he does not mention coroutines. I think coroutines with
their "yield" and "resume" are great mechanism to implement filters
and filter chains. They provide an easy and natural way to maintain
filter context while processing chunks of data. Also coroutines all
but eliminate (or rather hide) need for "pumps".
Is there any specific reason they are left out of this gem??

The original implementation actually used coroutines for the
filter chains. Unfortunately, this caused the library to
interfere poorly with pcall(), and some users complained.
The implementation of the smtp.message() function used as an
example the end of the Gem does use coroutines.

As to the relationship between pumps and coroutines, would
you mind clarifying?

Kind regards,
Diego

Reply | Threaded
Open this post in threaded view
|

Re: Lua Gems: Filters, Sources, Sinks and Pumps

Leo Razoumov
On 12/19/08, Diego Nehab <[hidden email]> wrote:
> Hi,
>
>
> > Now I am reading Diego Nehab's gem on "Filters, Sources, Sinks and Pumps".
> > To my surprise he does not mention coroutines. I think coroutines with
> > their "yield" and "resume" are great mechanism to implement filters
> > and filter chains. They provide an easy and natural way to maintain
> > filter context while processing chunks of data. Also coroutines all
> > but eliminate (or rather hide) need for "pumps".
> > Is there any specific reason they are left out of this gem??
> >
>
>  The original implementation actually used coroutines for the
>  filter chains. Unfortunately, this caused the library to
>  interfere poorly with pcall(), and some users complained.
>  The implementation of the smtp.message() function used as an
>  example the end of the Gem does use coroutines.
>
>  As to the relationship between pumps and coroutines, would
>  you mind clarifying?
>
>  Kind regards,
>  Diego

Diego,
thanks for your reply!

I think that with coroutines you do not need an explicit pump. For
example, in PiL2   Listing 9.1 (page 78)  "pumping loops" are part of
producer, consumer and filter.

Also, with coroutines one can do multi-rate processing when, for
example, filter_1 consumes two chunks of its input to generate one
chunk of output that it passes to filter_2 (in Digital Signal
Processing these things are fairly common)

Best regards,
--Leo--