diff options
Diffstat (limited to 'src/Environment.zig')
-rw-r--r-- | src/Environment.zig | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/Environment.zig b/src/Environment.zig index 34e6401..2fe9099 100644 --- a/src/Environment.zig +++ b/src/Environment.zig @@ -4,6 +4,7 @@ const SourceLocation = std.builtin.SourceLocation; const expectEqual = std.testing.expectEqual; +const expectError = std.testing.expectError; const std = @import("std"); const zeroes = std.mem.zeroes; @@ -11,6 +12,7 @@ const Value = zsanett.Value; const janet = @import("rename.zig").janet; const unwrap = zsanett.unwrap; const wrap = zsanett.wrap; +const wrapFn = zsanett.wrapFn; const zsanett = @import("root.zig"); const Environment = @This(); @@ -82,7 +84,7 @@ pub fn defn(comptime fun: anytype, reg: struct { const cfuns = [_]janet.RegExt{ .{ .name = reg.name, - .cfun = janet.unwrapCfunction(try wrap(fun)), + .cfun = try wrapFn(fun), .documentation = reg.documentation, .source_file = reg.source.file, .source_line = @bitCast(reg.source.line), @@ -107,4 +109,13 @@ test defn { .source = @src(), }); try expectEqual(try eval(i32, "(add 3 7)", @src().fn_name), 10); + + try defn(struct { + fn raise() !void { return error.ThisIsFine; } + }.raise, .{ + .name = "raise", + .documentation = "(raise)\n\nRaise an error.", + .source = @src(), + }); + try expectError(error.JanetError, eval(void, "(raise)", @src().fn_name)); } |