Module lousy.signal
lousy.signal library
Mimic the luakit signal API functions for tables.
Functions
lousy.signal.add_signal (object, signame, func)
Add a signal handler to an object, for a particular signal.
When a signal with the given name is emitted on the given object with
emit_signal()
, the given callback function will be called, along with all
other signal handlers for the signal on the object.
The first argument passed to the callback function will be the object this
signal is emitted on (object
), unless this object was setup for signals
with module=true
, i.e. as a module object. In that case, the object will
not be passed to the callback at all. Subsequently, the callback
function will receive all additional arguments passed to emit_signal()
.
object
must have been set up for signals with setup()
.
Parameters
-
objectType: any typeThe object on which to listen for signals.
-
signameType: stringThe name of the signal to listen for.
-
funcType: functionThe signal handler callback function.
lousy.signal.emit_signal (object, signame, ...)
Emit a signal on an object.
object
must have been set up for signals with setup()
.
Parameters
-
objectType: any typeThe object on which to emit the signal.
-
signameType: stringThe name of the signal to emit.
-
...Type: any typeAdditional arguments are passed any signal handlers called.
lousy.signal.remove_signal (object, signame, func)
Remove a signal handler function from an object.
object
must have been set up for signals with setup()
.
Parameters
-
objectType: any typeThe object on which to remove a signal handler.
-
signameType: stringThe name of the signal handler to remove.
-
funcType: functionThe signal handler callback function to remove.
Return Values
-
functionReturns the removed callback function, if the signal handler was found.
-
nilIf the signal handler was not found.
lousy.signal.remove_signals (object, signame)
Remove all signal handlers with a given name from an object.
Parameters
-
objectType: any typeThe object on which to remove a signal handler.
-
signameType: stringThe name of the signal handler to remove.
lousy.signal.setup (object, module)
Setup an object for signals.
Sets up the given object for signals, and returns the object.
If module
is true
, then the object is not passed to signal callback
functions as the first parameter when a signal is emitted.
object
must not have been set up for signals with setup()
.
Parameters
-
objectType: any typeThe object to set up for signals.
-
moduleType: booleanWhether this object should be treated as a module.
Return Values
-
any typeThe given object.
Attribution
Copyright
- 2010 Fabian Streitel
- 2010 Mason Larobina