Javascipt C/C++ calls

  • Follow


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
0
Reply Teo 5/10/2010 12:04:38 PM

Teo wrote:
> 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.
0
Reply Joe 5/10/2010 12:21:19 PM


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
0
Reply Erwin 5/10/2010 1:12:24 PM

On 10 Mag, 15:12, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spamyourself.com> wrote:
> 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).
> eghttp://www.example.com/myC_call.php?info=3D34
> and catch the output back.
>
> =A0From 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.
0
Reply Teo 5/10/2010 1:31:34 PM

On 10 Mag, 15:31, Teo <matteo.m...@gmail.com> wrote:
> On 10 Mag, 15:12, Erwin Moller
>
>
>
> <Since_humans_read_this_I_am_spammed_too_m...@spamyourself.com> wrote:
> > 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 ver=
y
> > > 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).
> > eghttp://www.example.com/myC_call.php?info=3D34
> > and catch the output back.
>
> > =A0From myC_call.php (or whatever serverside language suits you) you ca=
n
> > 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.

I need this to implement a binding for another technology.
0
Reply Teo 5/10/2010 1:33:21 PM

Teo wrote:
> 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?

--
Scott
0
Reply Scott 5/10/2010 1:35:48 PM

Teo wrote:
> On 10 Mag, 15:31, Teo <matteo.m...@gmail.com> wrote:
>> On 10 Mag, 15:12, Erwin Moller
>>
>>
>>
>> <Since_humans_read_this_I_am_spammed_too_m...@spamyourself.com> wrote:
>>> 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).
>>> 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.
> 
> 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.
0
Reply Joe 5/10/2010 1:46:51 PM

On May 10, 2:04=A0pm, Teo <matteo.m...@gmail.com> wrote:
> 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/library/documentation/AppleApplications=
/Conceptual/SafariJSProgTopics/Tasks/ObjCFromJavaScript.html
--
Jorge.
0
Reply Ry 5/10/2010 1:57:48 PM

On May 10, 3:57=A0pm, Ry Nohryb <jo...@jorgechamorro.com> wrote:
>
> 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/library/documentation/AppleApplication=
s/Conceptual/SafariJSProgTopics/Tasks/ObjCFromJavaScript.html

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

See also:
http://google.com/search?q=3DWebKit_PluginProgTopic+filetype:pdf+site:devel=
oper.apple.com
--
Jorge.
0
Reply Ry 5/10/2010 2:11:37 PM

On May 10, 4:11=A0pm, Ry Nohryb <jo...@jorgechamorro.com> wrote:
> On May 10, 3:57=A0pm, Ry Nohryb <jo...@jorgechamorro.com> wrote:
>
>
>
> > 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/library/documentation/AppleApplicati=
on...
>
> Sorry,http://nodejs.organdhttp://nodejs.org/api.html
>
> See also:http://google.com/search?q=3DWebKit_PluginProgTopic+filetype:pdf=
+site:d...
> --
> Jorge.

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.
--
Jorge.
0
Reply Ry 5/10/2010 2:31:59 PM

Ry Nohryb :

> 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 */

Why "for server-side JS" ?

-- 
Johannes
0
Reply Johannes 5/10/2010 3:27:03 PM

On May 10, 5:27=A0pm, Johannes Baagoe <baa...@baagoe.com> wrote:
> Ry Nohryb :
>
> > 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 */
>
> Why "for server-side JS" ?

Hmmm. I guess I mean: not in-browser: the API they provide is !=3D=3D that
the API that JS in a browser provides.
--
Jorge.
0
Reply Ry 5/10/2010 3:37:36 PM

Ry Nohryb :
> Johannes Baagoe :
>> Ry Nohryb :

>>> 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 */

>> Why "for server-side JS" ?

> Hmmm. I guess I mean: not in-browser: the API they provide is !==
> that the API that JS in a browser provides.

OK, as long as we don't forget that there are other applications than
Web servers and browsers :) Perhaps the best solution to the OP's
problem is a standalone application or a custom client that needs very
few of the functionalities of a full-fledged Web browser. Perhaps http,
html and the DOM are irrelevant.

Anyway, in addition to the links you provided, it may be worth the
trouble to take a look at http://live.gnome.org/Seed/

-- 
Johannes
0
Reply Johannes 5/10/2010 4:09:21 PM

Teo wrote:
> 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/library/documentation/Cocoa/Conceptual/DisplayWebContent/Tasks/JavaScriptFromObjC.html#//apple_ref/doc/uid/30001214-BCIIEAFH>
-- 
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
0
Reply Garrett 5/10/2010 5:05:14 PM

13 Replies
88 Views

(page loaded in 0.523 seconds)

Similiar Articles:


















7/19/2012 4:05:35 PM


Reply: