I'd like to find a way to call Javascript functions from C. Are there any language bindings available for this purpose? I'm trying to make a library of Javascript functions accessible from C. (Something like a C -> Javascript foreign function interface would be suitable for this purpose, but I haven't been able to find one so far.)
-
There are a few Javascript-to-C++ bindings available, but I need my Javascript functions to be invoked from C, not C++.– Anderson GreenAug 2, 2012 at 17:13
-
1Javascript doesn't make much sense without an engine. What exactly is the problem you're trying to solve here? Code reuse, or browser automation?– JordanAug 2, 2012 at 17:19
-
I'm w/ @Jordan, what is the problem you are trying to solve? What platforms? Why C and not C++?– DevSoloAug 2, 2012 at 18:07
-
I'm aiming for code reuse, not browser automation.– Anderson GreenAug 2, 2012 at 18:10
-
Also, I'd like it to be cross-platform.– Anderson GreenAug 2, 2012 at 18:11
1 Answer
There's quite a few Javascript engines you can use. Which one makes most sense will largely depend on your specific platform/target environments/needs.
There's the V8 javascript engine that powers Chrome, and Firefox's SpiderMonkey.
If Windows-only would suffice, you can use Active Scripting (IActiveScript site and other interfaces). A number of my Windows applications do this.
If QT, I believe they have their own JavaScript classes that can be accessed.
Thats not an exhaustive list, I'm sure there are others. But that should get your search started.
-
+1 for V8. I think that it's written in C++, you you could probably pretty easily wrap it in a C interface (if it doesn't have already).– LinuxiosAug 3, 2012 at 13:17