lua-users home
lua-l archive

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


On Tue, Sep 23, 2014 at 03:41:29PM -0300, Thiago L. wrote:
> On 23/09/14 03:18 PM, William Ahern wrote:
> >On Tue, Sep 23, 2014 at 02:23:12PM -0300, Thiago L. wrote:
> >>I'm writing an IRC library as the existing ones aren't really good
> >>enough (or pure Lua enough) for my purposes. I'm trying to decide on how
> >>to handle the messages, but I need some input.
> >>
> >>First method: (I prefer this way as I think it gives the coder more
> >>freedom, you can register a single handler and handle any number of
> >>events you want, and you can also use this to implement the 2nd method.
> >>I could also add priorities to this.)
> >>
> >>irc.addHandler(coroutine.create(function(...)
> >>     while true do
> >>         -- something here
> >>         coroutine.yield()
> >>     end
> >>end))
> ><snip>
> >>Second method: (this is how LuaIRC does it... not very friendly,
> >>especially when you're doing a modular bot...)
> >>
> >>irc.addHandler("eventName", function(...)
> >>end)
> >>
> >>So, what do you say? Should I go for the 1st or the 2nd method, or
> >>should I go for something else entirely?
> >IMO both of these options are too high-level and make too many assumptions
> >about the caller. I dislike APIs which make too many assumptions. I'd 
> >rather
> >they make fewer assumptions, but make it trivial for me to extend things.
>
> What do you mean too many assumptions about the caller?

For one thing, that the library users wants to handle events through a
callback (push rather than pull). Depending on how the object acquires
input, that the event dispatcher will loop indepenently rather than being
controlled in a step-by-step fashion by the library user.

Google "push pull parsing". It's generally considered that pull parsers are
much easier to integrate into applications. For example,

	http://docs.oracle.com/cd/E19316-01/819-3669/bnbdy/index.html