diff --git a/src/nu.zig b/src/nu.zig index 887515b..72638e4 100644 --- a/src/nu.zig +++ b/src/nu.zig @@ -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); - } - } -}