https://github.com/superzazu/signals.lua
Simple signals implementation in Lua.
https://github.com/superzazu/signals.lua
library observer-pattern signals
Last synced: about 1 year ago
JSON representation
Simple signals implementation in Lua.
- Host: GitHub
- URL: https://github.com/superzazu/signals.lua
- Owner: superzazu
- Created: 2015-05-26T20:36:28.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2017-04-08T14:51:49.000Z (almost 9 years ago)
- Last Synced: 2025-01-27T12:49:34.404Z (about 1 year ago)
- Topics: library, observer-pattern, signals
- Language: Lua
- Homepage:
- Size: 8.79 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# signals
signals is a simple signals module for Lua.
## Simple use
```
local signals = require "signals"
local monster = {is_alive=true}
signals.connect("player_hit_monster", function()
monster.is_alive = false
end)
signals.send("player_hit_monster")
print(monster.is_alive) -- false
```
## Use of groups
Sometimes, you'll probably want to disconnect a lot of signals at once:
```
local score = 0
signals.connect("player_hit_monster", function()
score = score + 10
end, "group1")
signals.connect("player_hit_monster", function()
score = score + 42
end, "group1")
signals.disconnectGroup("group1")
signals.send("player_hit_monster")
print(score) -- 0
```