By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,341 Members | 1,681 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,341 IT Pros & Developers. It's quick & easy.

Non Web-Based JavaScript, call C++ function

P: 7
Hey everyone. I'm trying to figure out how to call a C++ function from javascript. Everywhere I look, I'm just getting web-based answers and that won't help me. I'm working on a program that runs javascript while a machine is running, and I need this script to call a C++ function along the way, but can't figure out how. Any help? Even the most basic answer such as how to get a "Hello world" C++ funtion to run will be sufficient. Thanks!
Dec 6 '12 #1
Share this Question
Share on Google+
12 Replies


Dormilich
Expert Mod 5K+
P: 8,639
where does the JavaScript run? in a browser or (like node.js) in the console?

if the JS runs in a browser, you canít call a C++ function directly. you have to take a roundtrip and call a server script that runs the function for you.
Dec 6 '12 #2

P: 7
It runs in the console. Once a machine starts running, it executes a xxx.js file which processes the information. There is no indication on the computer that anything is happening at all. I just need this .js to call on some C++ functions.
Dec 6 '12 #3

Dormilich
Expert Mod 5K+
P: 8,639
then it depends on the File System API that your JS host provides.

but even then, you can only call an app/script that runs the C++ for you. there is no way for JS to directly call another language’s function.
Dec 6 '12 #4

P: 7
How do I go about calling a script to execute the C++?
Dec 6 '12 #5

Dormilich
Expert Mod 5K+
P: 8,639
that depends on the API that is available to JS.
Dec 6 '12 #6

P: 7
I am not aware of the API. I will have to do some digging.
Dec 6 '12 #7

Dormilich
Expert Mod 5K+
P: 8,639
you may look at node.js, that’s also a console based JS implementation, so you might get some ideas.
Dec 6 '12 #8

P: 7
There is a funtion in the .js file that causes an arm to move and creates a database recording whther or not it runs in to something. Once the function completes, the robot software requires C++ to create a database and report that records pass/fail results if there were objects that it ran in to. I just need the javascript to call on the C++ scripting at the end of its routine to create the database and report. I don't know what all there is as far as API, other than I use a simple .js to execute commands for the robot and I need it to somehow activate a C++ script.
Dec 6 '12 #9

Dormilich
Expert Mod 5K+
P: 8,639
asked the other way round, what application is running the JS?
Dec 6 '12 #10

P: 7
It's a machining program called Technomatix.
Dec 6 '12 #11

Dormilich
Expert Mod 5K+
P: 8,639
then you would need to read the Technomatix documentation to find any info about an API that lets you communicate with other applications.
Dec 6 '12 #12

P: 7
I just returned from a meeting on the project, and it turns out that my boss has some code from the company that he held from me. He likes to make me work I guess. Thanks for the input!
Dec 6 '12 #13

Post your reply

Sign in to post your reply or Sign up for a free account.