Hi,
I’ve put together a new Lua mod called Eventable. It’s basically a chat room for your tables and mods.
The module does not use any Corona based listeners, and does not rely on any ‘global’ space. Your tables are still just tables, with a couple extra methods. The API is small and simple.
There are a lot of examples on the Eventable site, but just to show how simple it is.
[lua]
– Require Eventable
local et = require(‘Eventable’)
– A new evented table
local mytbl = et:new()
– Listen for the ‘game’ event
mytbl:on(‘game’, function( event, score, players, … )
print( score, players )
end
– Send out a ‘greeting’ event.
mytbl:emit( ‘greeting’, 'Hello! )
[/lua]
Any evented
table or module can communicate with any other, as long as they are listening for the event.
[lua]
– Require Eventable
local et = require(‘Eventable’)
– Generate a couple evented
tables
local t1 = et:new()
local t2 = et:new()
– t1 listenens
t1:on(‘greeting’, function( event, message )
print( 'greeting: ’ … message )
end
– t2 sends
t2:emit(‘greeting’, ‘Hello!’)
–> greeting: Hello!
[/lua]
Visit the Eventable project site for more examples, including intra-module communication. You can also jump to the API here.
Testing, feedback, bug reporting highly appreciated.
Cheers.