Earlier quoted context omitted.
It's also important to point out ports, because as you mention, NIFs are a way to integrate external code. But as someone else points out, NIFs can crash the entire BEAM VM. Ports are a safer way to integrate external code because they are just another BEAM process that talks to an external program. If that program crashes, then the port process crashes just like any other BEAM process but it won't crash the entire B…
Why would anyone use a NIF instead of a Port then?
Zigler: Zig NIFs in Elixir
51–60 of 93 posts
Re: Zigler: Zig NIFs in Elixir
#52Does anyone actually enjoy using these systems that encourage you to embed programming-language X code in programming-language Y heredocs? I always find actually doing that — and then maintaining the results over time — to be quite painful: you don't get syntax highlighting inside the string; you can no longer search your worktree reliably using extension-based filtering; etc. I personally find the workflow much more…
That being said, you can get IDE language support for embedded code if you use eMacs or vim (and probably other editors as well). As I mentioned I still vastly prefer separating it personally, especially if you don’t necessarily expect your Python or Typescript programmers to be knowledgeable about Zig (or C).
Re: Zigler: Zig NIFs in Elixir
#53For 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…
Forgive me if I'm mixing up my terminology it's been a bit since I have poked at Elixir.
Re: Zigler: Zig NIFs in Elixir
#54For 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…
Do nifs have the equal process time stuff that regular elixir processes have? Where the BEAM will move the scheduler into another process if it's taking too long? Forgive me if I'm mixing up my terminology it's been a bit since I have poked at Elixir.
Here’s a link I found talking about using the dirty scheduler with Rust(ler): https://bgmarx.com/2018/08/15/using-dirty-schedulers-with-ru...
Re: Zigler: Zig NIFs in Elixir
#55Does anyone actually enjoy using these systems that encourage you to embed programming-language X code in programming-language Y heredocs? I always find actually doing that — and then maintaining the results over time — to be quite painful: you don't get syntax highlighting inside the string; you can no longer search your worktree reliably using extension-based filtering; etc. I personally find the workflow much more…
Isn’t that essentially any web application?
Re: Zigler: Zig NIFs in Elixir
#56For 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…
Do nifs have the equal process time stuff that regular elixir processes have? Where the BEAM will move the scheduler into another process if it's taking too long? Forgive me if I'm mixing up my terminology it's been a bit since I have poked at Elixir.
https://www.erlang.org/doc/apps/erts/erl_nif#enif_schedule_n...
After all, many of the BIFs have been replaced internally by NIFs
And there's this, which would scare me:
https://erlang.org/documentation/doc-15.0-rc3/erts-15.0/doc/...
Re: Zigler: Zig NIFs in Elixir
#57Earlier quoted context omitted.
Hence why Rustler is of so much interest since it provides more protections against this happening. Discord is a big Erlang + Rustler user.
What kind of protections as opposed to Zigler?
Re: Zigler: Zig NIFs in Elixir
#58Earlier quoted context omitted.
> I use zig a lot in elixir nif, for things like audio and video processing Sounds interesting, is it open source? I am interested in seeing how the code layout looks like when mixing Zig and Elixir
I don't have open source code base to share but here it how it looks like: // the_nif.zig fn init_imp( env: ?*erl.ErlNifEnv, argc: c_int, argv: [*c]const erl.ERL_NIF_TERM, ) !erl.ERL_NIF_TERM { if (argc != 0) { return error.BadArg; } return try helpers.make("Hello world"); } export fn media_tools_init( env: ?*erl.ErlNifEnv, argc: c_int, argv: [*c]const erl.ERL_NIF_TERM, ) erl.ERL_NIF_TERM { return init_imp(env, argc,…
Re: Zigler: Zig NIFs in Elixir
#59Are 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
#60Earlier quoted context omitted.
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
Wait, erlang has sigils?