Skip to content

Commit

Permalink
Add enif_is_{port,fun,empty_list} NIF API
Browse files Browse the repository at this point in the history
  • Loading branch information
krestenkrab committed Oct 13, 2013
1 parent e9cc35a commit fdc0c47
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions jnif/jnif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
static JavaVM *jvm;

static jmethodID m_eobject__testReference;
static jmethodID m_eobject__testFunction;
static jmethodID m_eobject__testPort;

static jclass ERT_class;
static jmethodID m_ERT__badarg;
Expand Down Expand Up @@ -41,6 +43,20 @@ int enif_is_ref(ErlNifEnv* ee, ERL_NIF_TERM term)
return ok != JVM_NULL;
}

int enif_is_fun(ErlNifEnv* ee, ERL_NIF_TERM term)
{
JNIEnv *je = ee->je;
jobject ok = je->CallObjectMethod((jobject)term, m_eobject__testFunction);
return ok != JVM_NULL;
}

int enif_is_port(ErlNifEnv* ee, ERL_NIF_TERM term)
{
JNIEnv *je = ee->je;
jobject ok = je->CallObjectMethod((jobject)term, m_eobject__testPort);
return ok != JVM_NULL;
}


ERL_NIF_TERM enif_make_badarg(ErlNifEnv* env)
{
Expand Down Expand Up @@ -229,6 +245,8 @@ static void init_jvm_data(JavaVM *vm, JNIEnv* je)

jclass eobject_class = je->FindClass("erjang/EObject");
m_eobject__testReference = je->GetMethodID(eobject_class, "testReference", "()Lerjang/ERef;");
m_eobject__testFunction = je->GetMethodID(eobject_class, "testFunction", "()Lerjang/EFun;");
m_eobject__testPort = je->GetMethodID(eobject_class, "testPort", "()Lerjang/EPort;");

ERT_class = je->FindClass("erjang/ERT");
ERT_class = (jclass)je->NewGlobalRef(ERT_class);
Expand Down
9 changes: 9 additions & 0 deletions jnif/jnif_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ static jclass eobject_class;
static jmethodID m_eobject__testCons;
static jmethodID m_eobject__testNonEmptyList;
static jmethodID m_eobject__testSeq;
static jmethodID m_eobject__isNil;

static jclass elist_class;
static jmethodID m_elist__make;
Expand All @@ -18,6 +19,11 @@ static jmethodID m_ERT__cons;

static jobject empty_list;

extern int enif_is_empty_list(ErlNifEnv *ee, ERL_NIF_TERM term)
{
return ee->je->CallBooleanMethod( E2J(term), m_eobject__isNil ) ? NIF_TRUE : NIF_FALSE;
}

extern int enif_is_list (ErlNifEnv* ee, ERL_NIF_TERM term)
{
jobject jterm = E2J(term);
Expand Down Expand Up @@ -106,6 +112,9 @@ void initialize_jnif_list(JavaVM* vm, JNIEnv *je)
m_eobject__testNonEmptyList = je->GetMethodID(eobject_class,
"testNonEmptyList",
"()Lerjang/ECons;");
m_eobject__isNil = je->GetMethodID(eobject_class,
"isNil",
"()Z");

elist_class = je->FindClass("erjang/EList");
elist_class = (jclass) je->NewGlobalRef(elist_class);
Expand Down

0 comments on commit fdc0c47

Please sign in to comment.