Zigler: Zig NIFs in Elixir
github.com
Zigler: Zig NIFs in Elixir
1–10 of 93 posts
Re: Zigler: Zig NIFs in Elixir
#2Re: Zigler: Zig NIFs in Elixir
#3Re: Zigler: Zig NIFs in Elixir
#4Re: Zigler: Zig NIFs in Elixir
#5Re: Zigler: Zig NIFs in Elixir
#6Great! But, what is a nifs, please? :'D
Re: Zigler: Zig NIFs in Elixir
#7The BEAM VM (which is the thing that runs erlang / elixir / gleam / etc) has 3 flavors of functions.
- BIFs - Built-in functions, these are written in C and ship with the VM
- NIFs - Natively implemented functions, these are written in any language that can speak the NIF ABI that BEAM exposes and allows you to provide a function that looks like a built-in function but that you build yourself.
- User - User functions are written in the language that's running on BEAM, so if you write a function in erlang or elixir, that's a user function.
NIFs allow you to drop down into a lower level language and extend the VM. Originally most NIFs were written in C, but now a lot more languages have built out nice facilities for writing NIFs. Rust has Rustler and Zig now has Zigler, although people have been writing zig nifs for a while without zigler and I'm sure people wrote rust nifs without rustler.
Re: Zigler: Zig NIFs in Elixir
#8Are sigils (~) restricted to one char? To me seems ~Zig would be more clear and short enough.
Elixir sigils also allow multiple characters in the name, but chars after the first must be upper case, according to the docs.
So for Elixir, it would have to be something like ~zIG
Re: Zigler: Zig NIFs in Elixir
#9For anyone mystified about what a NIF is that doesn't want to go read the docs. The BEAM VM (which is the thing that runs erlang / elixir / gleam / etc) has 3 flavors of functions. - BIFs - Built-in functions, these are written in C and ship with the VM - NIFs - Natively implemented functions, these are written in any language that can speak the NIF ABI that BEAM exposes and allows you to provide a function that look…
Re: Zigler: Zig NIFs in Elixir
#10For anyone mystified about what a NIF is that doesn't want to go read the docs. The BEAM VM (which is the thing that runs erlang / elixir / gleam / etc) has 3 flavors of functions. - BIFs - Built-in functions, these are written in C and ship with the VM - NIFs - Natively implemented functions, these are written in any language that can speak the NIF ABI that BEAM exposes and allows you to provide a function that look…
It’s important to note that while Erlang has protections against user code crashing an Erlang process and recovering, a faulty NIF can take down the entire virtual machine.
Discord is a big Erlang + Rustler user.