0

I have a JavaScript class, that I don't want to port to C++ as it is too huge and complicated. Is Is there any way in which I could call JavaScript functions from inside my C++ code.

4 Answers 4

2

I suggest you to check out Google's V8 a C++ Javascript Engine used in Chrome http://code.google.com/p/v8/

Sign up to request clarification or add additional context in comments.

Comments

2

You could embed a JavaScript engine, such as V8. It's a pretty (very) big overhead though. Unless you have a specific need, it would probably be better to just port your code.

Comments

1

Unless you have a very specific requirement that forces you to do this, this would be a very bad idea. It'll have a terrible overhead (in terms of execution speed and memory usage). You should seriously consider porting your Javascript code to C++.

6 Comments

I am trying to port this library ( depts.washington.edu/aimgroup/proj/dollar/ndollar.js ) . It's too long and complicated that's why i am searching for alternatives .
I have to tell you, it doesn't seem that complicated after a first (admittedly short) glance. :) I'd definitely port it, especially if the code involves math. It'll be an order of magnitude faster in C++ plus you can debug it if there are problems. You won't be able to debug Javascript code. (I don't know V8, so I don't know what debugging you could do with that.)
I just took another look to see if my quick look was wrong, but that Javascript is pretty short, you could probably port it in 2 days. (Assuming you know C++.) It's pretty simple logic to deal with vector math. You'll likely have more headaches if you tried integrating V8 instead of porting this.
The problem is that, i don't know the basics of javascript (As i have mentioned in the question ) . Anyway i will try to port it will let you know if i have any success .
@rajat if you know C++, that bit of Javascript should be no issue to you. Even if there are blocks in there that you can't figure out yourself, you can just ask about those here on SO. (I'm not a JS expert by any means but I'm willing to bet it'd take you longer to call that from C++ instead of porting it.)
|
1

You can use the V8 library to call JavaScript code from C++.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.