How to execute Javascript function in C++

前端 未结 4 1150
南笙
南笙 2020-12-03 02:14

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 nee

相关标签:
4条回答
  • 2020-12-03 02:36

    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.

    0 讨论(0)
  • 2020-12-03 02:39

    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:

    1. The Mozilla project's SpiderMonkey.
    2. Google Chrome's V8.
    3. A whole bunch of others.
    0 讨论(0)
  • 2020-12-03 02:39

    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.

    0 讨论(0)
  • 2020-12-03 02:48

    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.

    0 讨论(0)
提交回复
热议问题