Jump to content

Multiple events passed to addEventHandler.


steadyfi

Recommended Posts

Hello. While I was coding, I realized one thing:

It would be awesome if you could pass a table of events to a addEventHandler() function.

Example:

addEventHandler("event1", getRootElement(), function() 
    -- This will listen to only one event, passed in the first argument. 
end); 
addEventHandler({"event1", "event2"}, getRootElement(), function() 
    -- This will listen to multiple events, passed as a table in the first argument. 
end); 

There are times when you only want a anonymous function, but you gotta listen to multiple events, and you end up with really long names, usually which don't make sense, just to not interfere with the other functions.

This shouldn't be hard to implement, as far as I know. Just overload the addEventHandler() ;D.

I hope this makes sense. Have a great day! ;)

Link to comment
function addEventHandlerMultiple(events, ...) 
    for k, event in pairs(events) do 
        addEventHandler(event, ...) 
    end 
end 

Thanks for the reply!

I know I could've done something like that, I was just saying that it would've been I nice feature to be implemented to the Lua API.

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...