Learn to create a NIF. Receive two string inside my NIF. Please review.

I Gusti Ngurah Oka Prinarjaya okaprinarjaya@REDACTED
Tue Mar 31 20:08:18 CEST 2020


I learn to create a NIF. Inside my NIF, i need to receive two value, each
value is from paramA, and paramB.

type of value that i want to receive is string value. I need your help to
review my code
i afraid my code will crashing the VM.

My NIF successfully, and i get the expected result.

this is my code. please review.

// test_nif.c

static ERL_NIF_TERM lcs(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
int ret;
char A[50];
char B[50];
enif_get_string(env, argv[0], &A, 50, ERL_NIF_LATIN1);
enif_get_string(env, argv[1], &B, 50, ERL_NIF_LATIN1);
uint32_t lenA = strlen(A);
uint32_t lenB = strlen(B);

ret = llcs_utf8_int(A, B, lenA, lenB);
return enif_make_int(env, ret);

static ErlNifFunc nif_funcs[] = {
{"lcs", 2, lcs}

ERL_NIF_INIT(test_nif, nif_funcs, NULL, NULL, NULL, NULL)


test_nif:lcs("Hello World", "Hellaoo World").

Thank you
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20200401/d1660b48/attachment.htm>

More information about the erlang-questions mailing list