From 784e654f07ff8098d26439f506048d84d6d5e7d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Fri, 14 Feb 2025 20:04:38 +0300 Subject: [PATCH] document signal class --- data/scripts/types/signal.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/data/scripts/types/signal.lua b/data/scripts/types/signal.lua index ec3a520..979bf47 100644 --- a/data/scripts/types/signal.lua +++ b/data/scripts/types/signal.lua @@ -1,17 +1,26 @@ -local util = require "util" +---@class Signal +local Signal = { + _connections = {} +} -local Signal = {} +local util = require "util" Signal.__index = Signal +---Connects f to this signal. When the signal is emmitted, this function will be called. +---@param f function function Signal:connect(f) util.list_insert_once(self._connections, f) end +---Disconnects f from this signal. +---@param f function function Signal:disconnect(f) util.list_remove_value(self._connections, f) end +---Emits the signal, calling the connecting functions with the provided params. +---@param ... any function Signal:emit(...) -- don't care about order for _, v in pairs(self._connections) do @@ -19,6 +28,8 @@ function Signal:emit(...) end end +---Constructs a new signal. +---@return Signal function Signal.new() local s = { _connections = {},