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.