This commit is contained in:
2024-07-09 23:37:19 -04:00
parent cc1a9fdabc
commit aaea1fcf2a

View File

@@ -32,6 +32,18 @@ pub fn run() !void {
try invoke_hook("nu_close", .{});
}
// todo specify hook type.
// - special handling for error unions
// - allow per-hook state somehow declared in the handler
pub fn invoke_hook(comptime name: []const u8, args: anytype) !void {
inline for (modules) |module| {
if (@hasDecl(module, name)) {
try invoke(@field(module, name), args);
}
}
}
fn invoke(func: anytype, args: anytype) !void {
if (@typeInfo(@TypeOf(func)).Fn.return_type) |R| {
switch (@typeInfo(R)) {
@@ -44,15 +56,3 @@ fn invoke(func: anytype, args: anytype) !void {
}
}
}
// todo specify hook type.
// - special handling for error unions
// - allow per-hook state somehow declared in the handler
pub fn invoke_hook(comptime name: []const u8, args: anytype) !void {
inline for (modules) |module| {
if (@hasDecl(module, name)) {
try invoke(@field(module, name), args);
}
}
}