So I just want to double check,

You want to call function fun, which is defined in javascript?


You’ll need to write the actual C interfacing code that calls the actual javascript method. This is something that, AFAIK, SWIG doesn’t handle.

Take a look at this example:

http://www.codeproject.com/Articles/28804/JavaScript-function-access-from-plain-C-An-example

 

Google also provides the V8 library that you can embed into C++

http://cplus.about.com/b/2009/01/26/using-javascript-in-your-c-applications.htm

 

that would allow you to make javascript calls from C / C++

 

in short:

calling C/C++ from javascript: SWIG

calling javascript from C/C++ : V8 library

 

if someone with more SWIG experience knows better, please feel free to correct me! J

 

From: Pankaj Kumar Sangra [mailto:pksangra23nitrkl@gmail.com]
Sent: Friday, December 21, 2012 9:47 PM
To: swig-user@lists.sourceforge.net
Subject: [Swig-user] Unable to call functions defined in javascript from C file.

 

Hello SWIG User's,

 

SWIG tool seems very good for binding the two languages. 

Actually, I'm making web app using SWIG Tool. I have created my example.c and example.i to expose necessary APIs of Clutter libraries.

But one API is using call back function which calls the local function. So, here my user defined function is written in javascript(.js file) which includes the logic by using the exposed APIs. All the API's are working fine by exposing them. but with only single and required API I'm not able to expose which requires for signals handling like(mouse click);

 

*************CODE PART FOR BETTER UNDERSTANDING OF PROBLEM*************

 

File 1: example.c 

gulong JS_g_signal_connect_stage( ClutterActor *object,    const char *name,        char* func,       ClutterActor *func_data)

{

           return (gulong)g_signal_connect(object, name, G_CALLBACK(fun), NULL );

}

//--------------------------------------------

File 2: example.i 

extern  gulong JS_g_signal_connect_stage( ClutterActor *object,    const char *name,        char* func,       ClutterActor *func_data);

//--------------------------------------------

File 3: example.js 

 JS_g_signal_connect_stage(actor, "button-press-event", "logicFunction",NULL);

 

//logicFunction is called when mouse click is happened on actor.

function logicFunction(actor ,a, c)

{

   //Logic written in it

}

 

//--------------------------------------------

 

Normally  function "g_signal_connect " is used as 

 g_signal_connect(object, name, G_CALLBACK(fun), NULL ); and "fun" is called on press button which is defined locally. It takes the address of function and running fine if I make APP  in C.

When I'm using this function in example.c it should get the start address of function defined in javascript. First, How it will get that address? Secondly If it gets, whether C compiler executes those script lines of function.

 

If same logic I would write  in example.c with the C syntax. It is working perfect. I would like to define my logicfunction  in javascript file and function "g_signal_connect" should call that function as a callback.

 

 

Please assist if any of you have any way to call that function successfully. Please send me your views, suggestions and code.

 

 

I require your support for my interest to do all this business.

 

Thanks in Advance,

 

Regards,

Pankaj Kumar Sangra