lua-users home
lua-l archive

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


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))

irc.addHandler(function(...)
    while true do
        -- something here
coroutine.yield() -- functions are automagically wrapped in coroutines
    end
end)

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?