Corona SDK Lua OOP

EventDispatcher docs

Documentation has been added for EventDispatcher in LDoc format, generated from the source file.

Here’s the basic usage:

local EvtD = require "EventDispatcher"

local dispatcher = EvtD()

-- listener as table
local listener = {
   eventName = function(event, ...)
      print(,, event.source)

-- listener as function
local function listener(event, ...)
    print(,, event.source)

dispatcher:addEventListener( "eventName", listener ) -- or
dispatcher:on( "eventName", listener )

dispatcher:once( "eventName", listener )

dispatcher:hasEventListener( "eventName", listener )

dispatcher:dispatchEvent( { name="eventName" } ) -- or
dispatcher:dispatchEvent( "eventName" ) -- or
dispatcher:emit( { name="eventName" } ) -- or
dispatcher:emit( "eventName" )

dispatcher:removeEventListener( "eventName", listener )

dispatcher:removeAllListeners( "eventName" ) -- or


All listeners receive the following fields in the parameter event table:

  • (name of the event)
  • (the listener itself)
  • event.source (the dispatcher)

Grab the latest code at Github.

Corona SDK Lua OOP

EventDispatcher update

Just a quick post that EventDispatcher has been updated with new features including new methods on(), emit(), once() that are similar to Node.js, a new method removeAllListeners(), and a debug function printListeners(). The on() and emit() methods are actually aliases to the addEventListener() and dispatchEvent() methods.

Chris Byerley (aka develephant) who developed and is using EventDispatcher under the hood for the game server client code. Check out his projects if you’re a Lua / Corona developer.

Here’s the original post for EventDispatcher if you wish to read about it.

Grab the latest code at Github.