-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot pass function as parameter to JX_CallFunction #745
Comments
JXValue params[1] = { callback };
JX_CallFunction(&fn, params, 1, &result); |
#include <stdbool.h>
#include "jx.h"
int main(int argc, char **argv)
{
JXValue cb;
JXValue fn;
JXValue out;
char *contents = "console.log('Engine started');";
JX_InitializeOnce("");
JX_InitializeNewEngine();
JX_DefineMainFile(contents);
JX_StartEngine();
JX_Loop();
JX_Evaluate("(function (x) { console.log(x); })", "", &cb);
JX_Evaluate("(function (cb) { console.log(typeof cb); console.log(cb); cb('test'); })", "", &fn);
JXValue params[1] = { cb };
JX_CallFunction(&fn, params, 1, &out);
JX_Loop();
JX_Free(&cb);
JX_Free(&fn);
JX_Free(&out);
JX_StopEngine();
return 0;
} Compiled and dynamically linked against libjx.so on Linux:
Where Same result:
EDIT: Thought maybe using C was the problem. Compiled with g++
Doesn't fix anything. |
You are passing "" as script parameter. Try:
|
By default JX_CallFunction wasn't considering function as a value type. This is sort of both bug and feature request. However, @helmutkian Thanks for the details cfb3cd3 fixes the issue. |
When I pass a JXValue with a type of RT_Function as a parameter to JX_CallFunction, it somehow gets transformed into a number.
What I expect to see is
What I actually see is
And the final line doesn't execute because it's attempting to call a number as if it was a function.
Any idea why this is? Am I doing something wrong?
The text was updated successfully, but these errors were encountered: