mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Documentation experiments
This commit is contained in:
@@ -12,13 +12,20 @@ function M.initialize(self)
|
||||
end
|
||||
|
||||
|
||||
--- Subscribe callback on event
|
||||
-- @function event:subscribe
|
||||
-- @tparam function callback Callback itself
|
||||
function M.subscribe(self, callback)
|
||||
assert(type(self) == "table", "You should subscribe to event with : syntax")
|
||||
assert(type(callback) == "function", "Callback should be function")
|
||||
|
||||
table.insert(self._callbacks, callback)
|
||||
end
|
||||
|
||||
|
||||
--- Unsubscribe callback on event
|
||||
-- @function event:unsubscribe
|
||||
-- @tparam function callback Callback itself
|
||||
function M.unsubscribe(self, callback)
|
||||
for i = 1, #self._callbacks do
|
||||
if self._callbacks[i] == callback then
|
||||
@@ -29,6 +36,9 @@ function M.unsubscribe(self, callback)
|
||||
end
|
||||
|
||||
|
||||
--- Trigger the event and call all subscribed callbacks
|
||||
-- @function event:trigger
|
||||
-- @param ... All event params
|
||||
function M.trigger(self, ...)
|
||||
for i = 1, #self._callbacks do
|
||||
self._callbacks[i](...)
|
||||
|
Reference in New Issue
Block a user