How to call `ERL_NIF_TERM` when I know that it is a funciton?

27 Views Asked by At

My goal is to write a NIF that calls arbitrary Erlang function like fun(N) -> N + 1 end. or {M, F, A}, or any other valid way to do it. I need to operaite on a result out of the Erlang function.

As far as I see, the docs don't say much about how to call ERL_NIF_TERM when I know for sure it is a function. As such I am stumbled upon the following code:

const ERL_NIF_TERM fun = ...; // does not matter how do I get it

if (!enif_is_fun(env, fun))
  goto BADARG; // report an error

// hm... how do I call the `fun`? 

After a brief investigation, I discovered the typedef struct { ... } ErlNifFunc, but I still - have no idea how to get it out from the ERL_NIF_TERM safely.

0

There are 0 best solutions below