// native sampleMethod void sampleMethod(JXValue *results, int argc) { for (int i = 0; i < argc; i++) { std::string str; ConvertResult(&results[i], str); if (compare_base[i] != str.c_str()[0]) { flush_console("FAIL! Item(%d) : %s \n", i, str.c_str()); exit(-1); } } JXValue out; // fnc represents the JS side function fnc = &results[9]; param1 = results + 3; param2 = results + 4; // call JS side fnc with 2 parameters and get // the result to 'out' JX_CallFunction(fnc, (results + 3), 2, &out); // make fnc persistent so we can call it later again // see 'int main' for second call JX_MakePersistent(fnc); JX_MakePersistent(param1); JX_MakePersistent(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?"); }
static void defineEventCB(JXValue *results, int argc) { if (!JX_IsFunction(results + 1)) { error_console("defineEventCB expects a function"); return; } JX_MakePersistent(results+1); eventCB = *(results + 1); }