local event = require("signal")()
event:on(function()
print("I've been fired! ๐")
end)
event:fire()
--> "I've been fired! ๐"If you are using luarocks, just run:
luarocks install signalise
Copy the signal.lua file somewhere where your Lua interpreter will be able to find it and require it accordingly:
local signal = require("signal")local event = signal.new()or
local event = signal()Creates and returns the event. It must be captured in a variable a in order for the events to take place.
eventis the object that must be used to perform the events - see the "Event methods" section below.
event:fire([...])Triggers the event, allowing for connections to run once until the event is fired again.
event- An event returned bysignal.new...- The optional arguments to be used for the connections
local connection = event:attach(callback)Executes the given callback function whenever the connected event gets fired with the event.fire method.
event- An event returned bysignal.newcallback- Must be a function, exectuted when the event gets firedconnection- The returned connection
local connection = event:once(callback)Works almost identically to event.fire, but only fires once before self detaching.
event- An event returned bysignal.newcallback- Must be a function, exectuted when the event gets firedconnection- The returned connection
connection:detach()Concludes the usage of the given connection object.
connectionis the object that is fundamental for executing callbacks
Install busted & luacheck luarocks install busted && luarocks install luacheck and run:
$ busted
$ luacheck signal.lua
This library is free software; you can redistribute and/or modify it under the terms of the MIT license. See LICENSE for details.