hooks can now be deleted

This commit is contained in:
Squibid 2025-12-14 20:41:26 -05:00
parent 49e0875a85
commit 8d980ad032
Signed by: squibid
GPG key ID: BECE5684D3C4005D
4 changed files with 45 additions and 20 deletions

View file

@ -4,6 +4,8 @@ const std = @import("std");
const Hook = @import("Hook.zig");
const server = &@import("../main.zig").server;
const Node = struct {
hook: *const Hook,
node: std.SinglyLinkedList.Node,
@ -36,8 +38,15 @@ pub fn put(self: *Events, key: []const u8, hook: *const Hook) !void {
ll.prepend(&data.node);
}
// TODO: figure out deletion
// pub fn del(self: *Events, key: ???) !void {}
pub fn del(self: *Events, key: []const u8, hook: *const Hook) void {
if (self.events.get(key)) |e| {
var node = e.first;
while (node) |n| : (node = n.next) {
const data: *Node = @fieldParentPtr("node", n);
if (data.hook.options.lua_cb_ref_idx == hook.options.lua_cb_ref_idx) e.remove(n);
}
}
}
pub fn exec(self: *Events, event: []const u8, args: anytype) void {
if (self.events.get(event)) |e| {

View file

@ -11,7 +11,7 @@ const Event = @import("Events.zig");
const RemoteLua = @import("../RemoteLua.zig");
const Lua = &@import("../main.zig").lua;
events: std.ArrayList([]const u8), // a list of events
events: [][]const u8, // a list of events
options: struct {
// group: []const u8, // TODO: do we need groups?
/// This is the location of the callback lua function in the lua registry