Packages

A semi-useful tool to generate boilerplate when you want to use a NIF in your project. You don't really want to use a NIF in your project, until you do. Then this might save you writing most of the boilerplate.

Current section

Files

Jump to
nifty templates nif.c.eex
Raw

templates/nif.c.eex

#ifdef __GNUC__
#define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
#else
#define UNUSED(x) UNUSED_ ## x
#endif
#include "erl_nif.h"
#include <stdio.h>
#include <strings.h>
#include <unistd.h>
static ERL_NIF_TERM _hello(ErlNifEnv* env, int UNUSED(arc), const ERL_NIF_TERM UNUSED(argv[]))
{
return enif_make_double(env, 0.0);
}
static ErlNifFunc nif_funcs[] =
{
{"_hello", 0, _hello, 0}
};
/* Change Elixir.NIF to the name you use in the project */
ERL_NIF_INIT(Elixir.<%= mod %>,nif_funcs,NULL,NULL,NULL,NULL)