-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e79887
commit 3091f5c
Showing
6 changed files
with
118 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const beam = @import("beam"); | ||
const e = @import("erl_nif"); | ||
const std = @import("std"); | ||
|
||
pub fn nif_with_flags(comptime name: [*c]const u8, comptime arity: usize, comptime f: anytype, comptime flags: u32) type { | ||
return struct { | ||
fn exported(env: beam.env, n: c_int, args: [*c]const beam.term) callconv(.C) beam.term { | ||
if (f(env, n, args)) |r| { | ||
return r; | ||
} else |err| { | ||
return e.enif_raise_exception(env, beam.make_atom(env, @errorName(err))); | ||
} | ||
} | ||
pub const entry = e.ErlNifFunc{ .name = name, .arity = arity, .fptr = exported, .flags = flags }; | ||
}; | ||
} | ||
|
||
pub fn nif(comptime name: [*c]const u8, comptime arity: usize, comptime f: anytype) type { | ||
return nif_with_flags(name, arity, f, 0); | ||
} | ||
|
||
pub fn wrap(comptime f: anytype) fn (env: beam.env, n: c_int, args: [*c]const beam.term) callconv(.C) beam.term { | ||
return nif("", 0, f).exported; | ||
} |