I've written a function in JavaScript. For example:
function myName(a)
{
var k=10;
print(k);
}
Is it possible to call myName
from C using JavaScriptCore? If so, how?
I've written a function in JavaScript. For example:
function myName(a)
{
var k=10;
print(k);
}
Is it possible to call myName
from C using JavaScriptCore? If so, how?
You may want to have a look at the Google's V8 project (It's written in C++, though). Which allows you to compile and execute a javascript program within a C++ program (with the help of the embeded v8 engine). Here is its Getting Started document page
Yes, you can. One way to do it is, from C, call JSEvaluateScript. Something like this:
JSStringRef script = JSStringCreateWithUTF8CString("myName()");
JSEvaluateScript(ctx, script, NULL, NULL, 0, NULL);
This assumes you've created ctx (a JSContextRef) using JSGlobalContextCreate and have already evaluated your script in that context (again using JSEvaluateScript) to add the myName function to that ctx.