-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib_calc_nif.c
48 lines (41 loc) · 1.21 KB
/
lib_calc_nif.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <erl_nif.h>
#include "lib_calc.h"
static ERL_NIF_TERM somar_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
int a, b, result;
enif_get_int(env, argv[0], &a);
enif_get_int(env, argv[1], &b);
result = somar(a, b);
return enif_make_int(env, result);
}
static ERL_NIF_TERM subtrair_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
int a, b, result;
enif_get_int(env, argv[0], &a);
enif_get_int(env, argv[1], &b);
result = subtrair(a, b);
return enif_make_int(env, result);
}
static ERL_NIF_TERM multiplicar_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
int a, b, result;
enif_get_int(env, argv[0], &a);
enif_get_int(env, argv[1], &b);
result = multiplicar(a, b);
return enif_make_int(env, result);
}
static ERL_NIF_TERM dividir_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
int a, b, result;
enif_get_int(env, argv[0], &a);
enif_get_int(env, argv[1], &b);
result = dividir(a, b);
return enif_make_int(env, result);
}
static ErlNifFunc nif_funcs[] = {
{"somar", 2, somar_nif},
{"subtrair", 2, subtrair_nif},
{"multiplicar", 2, multiplicar_nif},
{"dividir", 2, dividir_nif},
};
ERL_NIF_INIT(Elixir.Calc, nif_funcs, NULL, NULL, NULL, NULL)