Live data from Hacker News

Zigler: Zig NIFs in Elixir

github.com

1–10 of 93 posts

Re: Zigler: Zig NIFs in Elixir

#5
I use zig a lot in elixir nif, for things like audio and video processing, it works great. But I do not use zigler as I prefer the code to live in their own codebases. But zigler is really nice and it provides an easy way to do computational heavy tasks in elixir.

Re: Zigler: Zig NIFs in Elixir

#7
For 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 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

#8
post #3

Are sigils (~) restricted to one char? To me seems ~Zig would be more clear and short enough.

Erlang sigils are not, they can be any length, limited to characters allowed in atoms.

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

#9

For 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.

Re: Zigler: Zig NIFs in Elixir

#10
post #9

For 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.

Hence why Rustler is of so much interest since it provides more protections against this happening.

Discord is a big Erlang + Rustler user.

Post reply on HN