Zig binding for Emacs’s dynamic modules.
See https://jiacai2050.github.io/zig-emacs/
const std = @import("std");
const emacs = @import("emacs");
// Every module needs to call `module_init` in order to register with Emacs.
comptime {
emacs.module_init(@This());
}
fn add(e: emacs.Env, v1: emacs.Value, v2: emacs.Value) emacs.Value {
const a = e.extractInteger(v1);
const b = e.extractInteger(v2);
return e.makeInteger(a + b);
}
// Emacs dynamic module entrypoint
pub fn init(env: emacs.Env) c_int {
env.defineFunc(
"zig-add",
add,
// This make `zig-add` interactive.
.{ .interactive_spec = "nFirst number: \nnSecond number: " },
);
return 0;
}Compile this example with zig build, then load it into Emacs.
(module-load (expand-file-name "zig-out/lib/libzig-example.dylib"))
(zig-greeting "Jiacai")If everything is OK, you should see our greeting message in minibuffer.
zig-emacs support package manager introduced in Zig 0.11.
zig fetch --save=emacs https://github.com/jiacai2050/zig-emacs/archive/${COMMIT}.tar.gzReplace ${COMMIT} with a real one.