mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-21 18:59:32 -06:00
an initial skeleton for building a Java binding to the C runtime
This commit is contained in:
31
src/runtime/java/jpgf.c
Normal file
31
src/runtime/java/jpgf.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <pgf/pgf.h>
|
||||
#include <gu/mem.h>
|
||||
#include "org_grammaticalframework_PGF.h"
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_org_grammaticalframework_PGF_readPGF(JNIEnv *env, jclass cls, jstring s)
|
||||
{
|
||||
const char *fpath = (*env)->GetStringUTFChars(env, s, 0);
|
||||
|
||||
GuPool* pool = gu_new_pool();
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
|
||||
// Create an exception frame that catches all errors.
|
||||
GuExn* err = gu_new_exn(NULL, gu_kind(type), tmp_pool);
|
||||
|
||||
// Read the PGF grammar.
|
||||
PgfPGF* pgf = pgf_read(fpath, pool, err);
|
||||
if (!gu_ok(err)) {
|
||||
gu_pool_free(pool);
|
||||
gu_pool_free(tmp_pool);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, s, fpath);
|
||||
|
||||
jmethodID constrId = (*env)->GetMethodID(env, cls, "<init>", "(II)V");
|
||||
|
||||
return (*env)->NewObject(env, cls, constrId, (int) pool, (int) pgf);
|
||||
}
|
||||
Reference in New Issue
Block a user