For example, I have a js code, and I while like to write a simple console program that read this code, execute it, and print back the result. Is this possible to do so? If yes, how can I start doing this? Thank you.
Asked
Active
Viewed 142 times
1
-
look in to something like v8 or rhino... – Richard J. Ross III Oct 17 '11 at 16:01
-
is there anything related to dom in this js code? – wong2 Oct 17 '11 at 16:01
-
Of course it's possible. It's called an interpreter. There's at least a dozen of them, likely more if you count non-mainstream ones. – Oct 17 '11 at 16:01
-
@RichardJ.RossIII Rhino is Java, isn't it? – Vala Oct 17 '11 at 16:03
-
@Thor84no Yea, I forgot about that. Even still, you could ship the Rhino jar with your C application and run the jar inside your application. – Richard J. Ross III Oct 17 '11 at 16:19
-
1Yes, you could. But running a JVM to run a JS engine to interpret a script... It's all getting a little messier than it needs to be at that point. – Vala Oct 17 '11 at 16:21
-
I see. Thank you all, I will do some researches on this direction. – DNB5brims Oct 18 '11 at 09:44
1 Answers
6
You'd need a JS engine for C such as SpiderMonkey (which is the one FireFox uses). I'm not sure how easy that is to use though, there may be others that are better.

Vala
- 5,628
- 1
- 29
- 55
-
1This seems to be of interest: https://developer.mozilla.org/En/SpiderMonkey/JSAPI_User_Guide – Felix Kling Oct 17 '11 at 16:13