int main(int argc, char **args) { JX_Initialize(args[0], callback); JX_InitializeNewEngine(); JX_DefineMainFile(contents); JX_DefineExtension("sampleMethod", sampleMethod); JX_StartEngine(); while (JX_LoopOnce() != 0) usleep(1); JXValue *params[2] = {param1, param2}; JXValue out; // call fnc -> JS side function // we had made this variable persistent inside sampleMethod JX_CallFunction(fnc, *params, 2, &out); // we need to clear persistent and then free whenever we // are done with persistent values to not to leak JX_ClearPersistent(fnc); JX_Free(fnc); JX_ClearPersistent(param1); JX_Free(param1); JX_ClearPersistent(param2); JX_Free(param2); assert(JX_GetDataLength(&out) == 11 && "Expected return value was 'test{\"a\":3}"); JX_Free(&out); assert(out.data_ == NULL && out.size_ == 0 && "JX_FreeResultData leaks?"); JX_StopEngine(); }
JNIEXPORT void JNICALL Java_org_capriza_jxcore_jxcore_startEngine(JNIEnv *env, jobject thiz) { std::thread::id thread_id = std::this_thread::get_id(); std::ostringstream oss; oss << "startEngine called thread id: " << thread_id; std::string var = oss.str(); __android_log_print(ANDROID_LOG_DEBUG, APPNAME, var.c_str(), 1); try { JX_StartEngine(); } catch (int e) { __android_log_print(ANDROID_LOG_ERROR, APPNAME, "EXCEPTION IN JX_StartEngine", 1); } (void) pthread_once(&key_once, make_key); int *bgsStopped = (int *) malloc(sizeof(int)); *bgsStopped = 1; (void) pthread_setspecific(tlsKey, bgsStopped); int* isAlive = (int*) pthread_getspecific(tlsKey); std::ostringstream oss2; oss2 << "startEngine ended thread id: " << thread_id << " is Alive: " << *isAlive; std::string var2 = oss2.str(); __android_log_print(ANDROID_LOG_DEBUG, APPNAME, var2.c_str(), 1); }
int main(int argc, char **args) { JX_Initialize(args[0], callback); JX_InitializeNewEngine(); JX_DefineMainFile(contents); JX_DefineExtension("crashMe", crashMe); JX_DefineExtension("sampleMethod", sampleMethod); JX_StartEngine(); while (JX_LoopOnce() != 0) usleep(1); JX_StopEngine(); }
int main(int argc, char **args) { JX_InitializeOnce("/test/bin/cpp/"); JX_InitializeNewEngine(); JX_DefineMainFile(contents); JX_StartEngine(); JXValue ret_val; JX_Evaluate("process.callMe()", "eval", &ret_val); while (JX_LoopOnce() != 0) usleep(1); assert(JX_IsError(&ret_val) && "error was expected"); std::string str; ConvertResult(&ret_val, str); assert(!strcmp("TypeError: this is type exception", str.c_str()) && "Exception output doesn't match"); JX_Free(&ret_val); JX_StopEngine(); }
int main(int argc, char **args) { JX_Initialize(args[0], callback); JX_InitializeNewEngine(); JX_DefineMainFile(contents); JX_DefineExtension("sampleMethod", sampleMethod); JX_StartEngine(); // loop for possible IO // or JX_Loop() without usleep / while while (JX_LoopOnce() != 0) usleep(1); JXValue result; JX_Evaluate(eval_str, "myscript", &result); JX_Free(&result); // loop for possible IO // or JX_Loop() without usleep / while while (JX_LoopOnce() != 0) usleep(1); JX_StopEngine(); assert(counter == 3 && "sampleMethod is expected to recive 3 calls (2 sub instance, 1 main)"); }
int main(int argc, char **args) { JX_Initialize(args[0], callback); JX_InitializeNewEngine(); JX_DefineMainFile(contents); JX_StartEngine(); JXValue ret_val; // this is not a function, it shouldn't return. // exception is expected JX_Evaluate("return process.x", "eval", &ret_val); while (JX_LoopOnce() != 0) usleep(1); assert(JX_IsError(&ret_val) && "error was expected"); JX_Free(&ret_val); JX_StopEngine(); return 0; }
JNIEXPORT void JNICALL Java_io_jxcore_node_jxcore_startEngine(JNIEnv *env, jobject thiz) { JX_StartEngine(); }