Files
Bubberstation/lua/handler_group.lua
Y0SH1M4S73R d1ccb530b2 Replaces Auxlua with the byondapi-based Dreamluau (#84810)
## About The Pull Request

Ever since byondapi went stable, I've been meaning to create a
replacement lua library that uses it instead of the auxtools-based
auxlua. After so many months, I've finally got the code just about into
a position where it's ready for a PR.

[Click here](https://hackmd.io/@aloZJicNQrmfYgykhfFwAQ/BySAS18u0) for a
guide to rewriting auxlua scripts for dreamluau syntax.

## Why It's Good For The Game

Code that runs on production servers should not depend on memory hacks
that are liable to break any time Dream Daemon updates.

## Changelog

🆑
admin: Admin lua scripting uses a new library that (probably) will not
break when BYOND updates.
/🆑

## TODO:
- [x] Convert the lua editor ui to TS
- [x] Include a guide for converting scripts from auxlua syntax to
dreamluau syntax
2024-07-28 18:45:49 +00:00

49 lines
1.3 KiB
Lua

local SS13 = require("SS13")
local HandlerGroup = {}
HandlerGroup.__index = HandlerGroup
function HandlerGroup.new()
return setmetatable({
registered = {},
}, HandlerGroup)
end
-- Registers a signal on a datum for this handler group instance.
function HandlerGroup:register_signal(datum, signal, func)
local registered_successfully = SS13.register_signal(datum, signal, func)
if not registered_successfully then
return
end
table.insert(self.registered, { datum = datum, signal = signal, func = func })
end
-- Clears all the signals that have been registered on this HandlerGroup
function HandlerGroup:clear()
for _, data in self.registered do
if not data.func or not SS13.is_valid(data.datum) then
continue
end
SS13.unregister_signal(data.datum, data.signal, data.func)
end
table.clear(self.registered)
end
-- Clears all the signals that have been registered on this HandlerGroup when a specific signal is sent on a datum.
function HandlerGroup:clear_on(datum, signal, func)
SS13.register_signal(datum, signal, function(...)
if func then
func(...)
end
self:clear()
end)
end
-- Registers a signal on a datum and clears it after it is called once.
function HandlerGroup.register_once(datum, signal, func)
local callback = HandlerGroup.new()
callback:clear_on(datum, signal, func)
return callback
end
return HandlerGroup