mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-08 04:57:32 -04:00
hooks can now be deleted
This commit is contained in:
parent
49e0875a85
commit
8d980ad032
4 changed files with 45 additions and 20 deletions
|
|
@ -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| {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue