Reputation:
Please tell me, how to include a javascript header file or javascript function in C++ code. The C++ code is written in Linux(UBUNTU)?
Although i need to perform the above action only, but let me tell u my purpose of doing it, as i am intending to implement CTI (Computer Telephony Integration) operation.
(Help will be appreciated) Thanks a lot in advance
Upvotes: 11
Views: 52400
Reputation: 13434
Calling Scripting functions from C++
http://clipp.sourceforge.net/Tutorial/back_calling.html
JavaScript Calls from C++ - CodeGuru
http://www.codeguru.com/cpp/i-n/ieprogram/article.php/c4399/JavaScript-Calls-from-C.htm
JavaScript call from C++ - CodeProject
http://www.codeproject.com/KB/COM/jscalls.aspx
calling javascript from c++ code - JavaScript / Ajax / DHTML answers
http://bytes.com/topic/javascript/answers/759793-calling-javascript-c-code
Try All of above this.
Upvotes: 16
Reputation: 1719
A detailed tutorial for embedding JS in C++ via Mozilla's SpiderMonkey engine can be found here Basically you need to include jsapi.h, create/configure/cleanup the JS engine as the tutorial describes (populating the char* script with your string literal JS source code and passing the resulting character array to JS_EvaluateScript), and then link against the SpiderMonkey library when you build the executable for your system. Note that this tutorial goes on to explain how to call C functions from JS and how to call specific JS functions from C, which is also interesting and possibly more appropriate for the OP's situation.
Upvotes: 2
Reputation: 185852
JavaScript is not a compiled language and it is not, by any stretch of the imagination, compatible with C++, so #include
doesn't stand a chance of importing JavaScript code. In fact, the notion of a header file doesn't even exist in JavaScript.
There are several JavaScript engines that can be integrated into a compiled language, including:
Upvotes: 4
Reputation: 29009
You might want to port your JS to C++; this should be a fairly simple task, as the two languages are moderately alike.
Simply porting the functionality is likely to be far simpler than actually trying to use a JS parsing library, and likely less error prone.
Upvotes: 6