diff options
author | Sverker Eriksson <[email protected]> | 2010-04-28 10:21:36 +0000 |
---|---|---|
committer | Erlang/OTP <[email protected]> | 2010-04-28 10:21:36 +0000 |
commit | 933304e3dcce052eff6d36c37b708949e53597c3 (patch) | |
tree | 2ffd95992221fda3d31ec1cfe8ec41584b21bd07 /system/doc/tutorial/complex6_nif.c | |
parent | 39e5ca57147c08502806f873c107c77e197a78ab (diff) | |
download | otp-933304e3dcce052eff6d36c37b708949e53597c3.tar.gz otp-933304e3dcce052eff6d36c37b708949e53597c3.tar.bz2 otp-933304e3dcce052eff6d36c37b708949e53597c3.zip |
OTP-8474 NIF improvements after R13B04
New NIF API function enif_make_new_binary
Diffstat (limited to 'system/doc/tutorial/complex6_nif.c')
-rw-r--r-- | system/doc/tutorial/complex6_nif.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/system/doc/tutorial/complex6_nif.c b/system/doc/tutorial/complex6_nif.c new file mode 100644 index 0000000000..b656ed43ce --- /dev/null +++ b/system/doc/tutorial/complex6_nif.c @@ -0,0 +1,32 @@ +#include "erl_nif.h" + +extern int foo(int x); +extern int bar(int y); + +static ERL_NIF_TERM foo_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + int x, ret; + if (!enif_get_int(env, argv[0], &x)) { + return enif_make_badarg(env); + } + ret = foo(x); + return enif_make_int(env, ret); +} + +static ERL_NIF_TERM bar_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + int y, ret; + if (!enif_get_int(env, argv[0], &y)) { + return enif_make_badarg(env); + } + ret = bar(y); + return enif_make_int(env, ret); +} + +static ErlNifFunc nif_funcs[] = { + {"foo", 1, foo_nif}, + {"bar", 1, bar_nif} +}; + +ERL_NIF_INIT(complex6, nif_funcs, NULL, NULL, NULL, NULL) + |