Javascipt C/C++ calls

T

Teo

Hello,

I would like to know if it's possible to make C/C++ calls from
javascript, compiled in a static or dynamic library and included, and
in such a case how can I do that. Does someone know it? Thank you very
much. Any help would be very appreciated.

Regards
Matteo
 
J

Joe Nine

Teo said:
Hello,

I would like to know if it's possible to make C/C++ calls from
javascript, compiled in a static or dynamic library and included, and
in such a case how can I do that. Does someone know it? Thank you very
much. Any help would be very appreciated.

Regards
Matteo

From Java you can call C/C++

Java -> JNI -> C libraries

and from JavaScript you can call Java applets

JavaScript -> Java Applet

But I doubt you can complete the sequence from JavaScript to Java to JNI
to C because a Java Applet is trapped within a sandbox called the JVM
(Java Virtual Machine) and I'd be surprised if it lets you access JNI
and C libraries. If it did, then any webpage with an applet on it could
basically do anything at all on your machine.

All the above changes if your web page isn't on the web and can use hta
of course.
 
E

Erwin Moller

Teo schreef:
Hello,

I would like to know if it's possible to make C/C++ calls from
javascript, compiled in a static or dynamic library and included, and
in such a case how can I do that. Does someone know it? Thank you very
much. Any help would be very appreciated.

Regards
Matteo


Hi,

AFAIK: No, not from within a browser (unless it is broken).

You can of course make calls to your server and do over there whatever
you like (including calling your C libs) and return the output to your
JavaScript.

Something like:
JavaScript instantiates a XMLHTTPREQUEST object (AJAX).
eg http://www.example.com/myC_call.php?info=34
and catch the output back.

From myC_call.php (or whatever serverside language suits you) you can
call your C routines.

Of course, this solution will not be suitable for fast execution since
it needs a roundtrip to the server.

Maybe using a Java applet makes more sense in your situation. (This
involves writing your C code again in Java.)


Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
 
T

Teo

Teo schreef:




Hi,

AFAIK: No, not from within a browser (unless it is broken).

You can of course make calls to your server and do over there whatever
you like (including calling your C libs) and return the output to your
JavaScript.

Something like:
JavaScript instantiates a XMLHTTPREQUEST object (AJAX).
eghttp://www.example.com/myC_call.php?info=34
and catch the output back.

 From myC_call.php (or whatever serverside language suits you) you can
call your C routines.

Of course, this solution will not be suitable for fast execution since
it needs a roundtrip to the server.

Maybe using a Java applet makes more sense in your situation. (This
involves writing your C code again in Java.)

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare

Ok I'll explain myself better, maybe I tackled the problem from an
uncorrect point of view. I would need a way to "extend" Javascript, or
something like that, to make C calls. I understood that probably, like
you guys told me, it's not possible making directly the calls. I mean
something like extension features of python, ruby etc. Thank you a lot
agiain.
 
T

Teo

Ok I'll explain myself better, maybe I tackled the problem from an
uncorrect point of view. I would need a way to "extend" Javascript, or
something like that, to make C calls. I understood that probably, like
you guys told me, it's not possible making directly the calls. I mean
something like extension features of python, ruby etc. Thank you a lot
agiain.

I need this to implement a binding for another technology.
 
S

Scott Sauyet

Teo said:
Ok I'll explain myself better, maybe I tackled the problem from an
uncorrect point of view. I would need a way to "extend" Javascript, or
something like that, to make C calls. I understood that probably, like
you guys told me, it's not possible making directly the calls. I mean
something like extension features of python, ruby etc. Thank you a lot
agiain.

To run in what environment? In most web browsers, there are already
plug-in architectures that might help. Of course then your users
would have to be willing to install your plug-in. For other
environments, there are probably mechanisms that are useful too. So
where should this run?
 
J

Joe Nine

Teo said:
I need this to implement a binding for another technology.

If you're limiting usage to Internet Explorer then you can write an
ActiveX control which can call C dlls. It won't work on non-IE plugins
though as they're as sandboxed as Java is.
 
R

Ry Nohryb

Hello,

I would like to know if it's possible to make C/C++ calls from
javascript, compiled in a static or dynamic library and included, and
in such a case how can I do that. Does someone know it? Thank you very
much. Any help would be very appreciated.

Regards
Matteo

You can do that freely on a server running server-side JS (e.g.
Node.js [*1]), but not -normally- on a browser -unless you install a
plugin [*2] for that- where the JS code can't call nothing beyond the
provided secure sandboxed API.

(*1) http://node.js
(*2) http://developer.apple.com/Mac/libr...ariJSProgTopics/Tasks/ObjCFromJavaScript.html
 
R

Ry Nohryb

You can do that freely on a server running server-side JS (e.g.
Node.js [*1]), but not -normally- on a browser -unless you install a
plugin [*2] for that- where the JS code can't call nothing beyond the
provided secure sandboxed API.

(*1)http://node.js
(*2)http://developer.apple.com/Mac/libr...ariJSProgTopics/Tasks/ObjCFromJavaScript.html

Sorry, http://nodejs.org and http://nodejs.org/api.html

See also:
http://google.com/search?q=WebKit_PluginProgTopic+filetype:pdf+site:developer.apple.com
 
R

Ry Nohryb

You can do that freely on a server running server-side JS (e.g.
Node.js [*1]), but not -normally- on a browser -unless you install a
plugin [*2] for that- where the JS code can't call nothing beyond the
provided secure sandboxed API.

Sorry,http://nodejs.organdhttp://nodejs.org/api.html

See also:http://google.com/search?q=WebKit_PluginProgTopic+filetype:pdf+site:d...

For server-side JS there's :

https://wiki.mozilla.org/ServerJS/Existing_APIs
http://www.mozilla.org/js/spidermonkey/ /* Pure C! (but not too fast)
*/
http://code.google.com/p/v8/ /* Damn fast ! */
http://webkit.org/projects/javascript/ /* JavaScriptCore: Damn fast
too! ++Pure C API */

(My favourites: Node.js and http://www.jsdb.org/ )

Plus the WSH crap from Microsoft, heavily poisoned with ActiveX
bindings.
 
G

Garrett Smith

Teo said:
Hello,

I would like to know if it's possible to make C/C++ calls from
javascript, compiled in a static or dynamic library and included, and
in such a case how can I do that. Does someone know it? Thank you very
much. Any help would be very appreciated.
It is possible to create an application that wraps Webkit and expose an
API to the script environment.

I do not have any experience doing that. You might try WebKit
documentation.

Apple changes the location of their documents pretty frequently, so no
saying how long that link will be good for, but if the link is bad, then
search for the title:
"Using JavaScript From Objective-C"

The document is found at a long, unmemorable URI from Apple and it may
have information for what you are looking to do:

<http://developer.apple.com/mac/libr...jC.html#//apple_ref/doc/uid/30001214-BCIIEAFH>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,205
Latest member
ElwoodDurh

Latest Threads

Top