Hey … I am quite new to Solar2D (and to be honest I am impressed with) . I have been trying out Love2D for quite some time in the past - so I was just curious, is there something similar to hump.signal aka the Observer pattern in the Solar2D world? Be it a Lua component or a Solar2D Library.
-
Solar2d already has an Observer pattern implementation in EventDispatcher:
https://docs.coronalabs.com/api/type/EventDispatcher/index.html -
hump.signal seems to be a pure Lua library. Those can be used as-is in your Solar2d project just by adding them anywhere in the main directory and then accessing them using the correct notation (“folder.filename”)
I use option 1 all the time like this:
eventDispatcher:addEventListener("ads", function()
-- Do something.
end)
Which would be the equivalent of:
Signal.register('ads', function()
--Do something
end)
Emit or dispatch an event:
dispatcher:dispatchEvent( { name="ads", type=event.type,provider=adProvider.providerName } )
or
Signal.emit('ads', event.type, adProvider.providerName, )
1 Like
Aaah nice. Thanks so much. Was really looking for this.
Yes, it does seem like pure Lua, but in essence didn’t want to be caught off-guard by a Love2D specific implementation just in case.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.