erlang + Zig NIF example
erl 25
zig 0.13.0
(l)ubuntu 22.04 lts
// zig build-lib -dynamic niftest.zig -I $ERL_ROOT/usr/include --library c -femit-bin=niftest.so
$ zig build-lib -dynamic niftest.zig -I $HOME/.kerl/erlangs/25.3/usr/include --library c -femit-bin=niftest.so
$ erl
Erlang/OTP 25 [erts-13.2] [source] [64-bit] [smp:20:20] [ds:20:20:10] [async-threads:1] [jit:ns]
Eshell V13.2 (abort with ^G)
1> c(niftest).
{ok,niftest}
2> niftest:hello().
"Hello world!"
3> niftest:factorial(5).
<<"x">>
4> binary:decode_unsigned(niftest:factorial(5)).
120
5> niftest:factorial(20).
<<33,195,103,124,130,180,0,0>>
6> binary:decode_unsigned(niftest:factorial(20)).
2432902008176640000
7> niftest:factorial(34).
<<222,27,196,209,158,252,172,130,68,93,167,91,0,0,0,0>>
8> binary:decode_unsigned(niftest:factorial(34)).
295232799039604140847618609643520000000
9> niftest:factorial(35).
{error,"input too large, max is 34"}
10> niftest:factorial(-5).
** exception error: bad argument
in function niftest:factorial/1
called as niftest:factorial(-5)
11> q().
ok
https://www.erlang.org/docs/25/man/erl_nif.html
https://www.erlang.org/doc/system/nif.html
https://www.erlang.org/doc/system/debugging.html