Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
britzl committed Apr 2, 2019
1 parent beafd06 commit 76db73b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ Wrap engine callbacks from iac, iap, push and window. Refer to [app.md](ludobits
Create bezier curves

### ludobits.m.broadcast
Broadcast messages and set up optional function callbacks when messages are received. Refer to [broadcast.md](ludobits/m/broadcast.md) for usage details.
Broadcast Defold messages (using msg.post) and set up optional function callbacks when messages are received. Refer to [broadcast.md](ludobits/m/broadcast.md) for usage details.

### ludobits.m.flow
Simplifies asynchronous flows of execution where your code needs to wait for one asynchronous operation to finish before tarting with the next one.

### ludobits.m.json
JSON encode
JSON encode (using rxi.json)

### ludobits.m.listener
Listener implementation where listeners are added as either urls or functions and notified when any or specific messages are received. Refer to [listener.md](ludobits/m/listener.md) for usage details.
Expand Down
25 changes: 18 additions & 7 deletions ludobits/m/broadcast.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,33 @@ Module to simplify sending of a message to multiple receivers

## Usage

-- script_a.script
-- receiver_a.script
local broadcast = require "ludobits.m.broadcast"

function init(self)
-- this script should react to "foo" and "bar" messages
broadcast.register("foo")
end

function final(self)
broadcast.unregister("foo")
end

function on_message(self, message_id, message, sender)
if message_id == hash("foo") then
-- handle message "foo"
end
end

-- receiver_b.script
local broadcast = require "ludobits.m.broadcast"

function init(self)
broadcast.register("bar", function(message, sender)
-- handle message
end)
end

function final(self)
broadcast.unregister("foo")
broadcast.unregister("bar")
end

Expand All @@ -24,13 +38,10 @@ Module to simplify sending of a message to multiple receivers
-- message was handled
return
end
if message_id == hash("foo") then
-- handle message "foo"
end
end


-- script_b.script
-- broadcaster.script
local broadcast = require "ludobits.m.broadcast"

function update(self, dt)
Expand Down

0 comments on commit 76db73b

Please sign in to comment.