Skip to content

Commit ce13d41

Browse files
committed
Add ScreenManager.publish
This function allows users to pass messages to other screens in the stack.
1 parent b548006 commit ce13d41

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

ScreenManager.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,19 @@ function ScreenManager.pop()
223223
end
224224
end
225225

226+
---
227+
-- Publishes a message to all screens which have a public receive function.
228+
-- @tparam string event A string by which the message can be identified.
229+
-- @tparam varargs ... Multiple parameters to push to the receiver.
230+
--
231+
function ScreenManager.publish( event, ... )
232+
for i = 1, #stack do
233+
if stack[i].receive then
234+
stack[i]:receive( event, ... )
235+
end
236+
end
237+
end
238+
226239
-- ------------------------------------------------
227240
-- LOVE Callbacks
228241
-- ------------------------------------------------

0 commit comments

Comments
 (0)