JNIEXPORT long JNICALL Java_com_torchandroid_facedemo_CameraClass_initTorch(JNIEnv *env, jobject thiz, jobject assetManager) { // get native asset manager. This allows access to files stored in the assets folder AAssetManager* manager = AAssetManager_fromJava(env, assetManager); assert( NULL != manager); lua_State *L = NULL; L = inittorch(manager); // create a lua_State // load and run file char file[] = "main.lua"; int ret; long size = android_asset_get_size(file); if (size != -1) { char *filebytes = android_asset_get_bytes(file); ret = luaL_dobuffer(L, filebytes, size, "main"); if (ret == 1) { D("Torch Error doing resource: %s\n", file); D(lua_tostring(L,-1)); } else { D("Torch script ran succesfully."); } } lua_register(L,"parse",parse); //This function is used by main.lua. return (long) L; }
JNIEXPORT long JNICALL Java_com_torchandroid_neuraltalk_lua_LuaManager_initTorch(JNIEnv *env, jobject thiz, jobject assetManager, jstring nativeLibraryDir_) { // get native asset manager. This allows access to files stored in the assets folder AAssetManager* manager = AAssetManager_fromJava(env, assetManager); assert( NULL != manager); const char *nativeLibraryDir = env->GetStringUTFChars(nativeLibraryDir_, 0); lua_State *L = NULL; L = inittorch(manager, nativeLibraryDir);// create a lua_State // load and run file char file[] = "init-only.lua"; int ret; long size = android_asset_get_size(file); if (size != -1) { char *filebytes = android_asset_get_bytes(file); ret = luaL_dobuffer(L, filebytes, size, "init-only"); if (ret == 1) { D("Torch Error doing resource: %s\n", file); D(lua_tostring(L,-1)); } else { D("Torch script ran successfully."); } } return (long) L; }