Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #14903

Re: Extending JavaScript (C lib)

From "Scott Sauyet" <3103invalid@webnews.fastusenet.org>
Newsgroups comp.lang.javascript
Subject Re: Extending JavaScript (C lib)
Message-ID <201207061205233103@webnews.fastusenet.org> (permalink)
References <23cade81-201f-4f8c-92dc-110870559add@googlegroups.com> <XnsA088653FBA3EDeejj99@194.109.133.133>
Date 2012-07-06 12:05 +0000

Show all headers | View raw


Evertjan wrote:
> Mathieu wrote:
>> 
>>   I am slowly discovering the JavaScript world, and I would like to
>>   know how I can extend JavaScript to use one of my custom C lib. I
>>   have seen dozens of different solutions (libffi, mosync,
>>   js-ctypes...) but I can't seem to find a solution that is: 
>> - portable (across recent browsers),
>> - efficient in term of speed,
>> - safe (in term of coding)
>> 
>> libffi seems ok, but it requires the JavaScript programmer to know the
>> ABI of the C function, so this does not scale well as new functions
>> are added or old ones are changed... 
>
> [please us a sig on usenet]

Why?

> That does not seem very practical.
> 
> Javascript being a loose-typed scripting language 
> and C a strict-typed compiling one.
> 
> Javascript has to run on different engines and didfferent versions 
> of those languages, all having diferent levels of implementations,
> with M$ being the  main culprit of noncompliance.

I think you're crossing levels here.  Mathieu is talking about extensions 
to the language, which is usually implemented, I believe, in C.  I know 
that Rhino is a Java project, and there are other non-C implementations, 
and I'm really only guessing.  Can someone enlighten us definitively on 
the main implementations?

So to write an extension to the language, it would probably make the most 
sense to write it in the language used to implement the target language.  

For instance, Javascript has, as well as the very generic Object and Array 
constructors, much more specific Date and RegExp ones built in.  Perhaps 
Mathieu wants to do image processing and would really like a Color 
constructor built into the language, one that would be more efficient than 
something you might build in the language with red, green, and blue 
properties, or even with a three integer array.  That could be done, if he 
had access to the source code of the language by adding a new native Color 
constructor, written in C, and optimized beyond what might be available 
inside Javascript itself.

I will respond separately to the original post as to my thoughts on the 
feasibility of Mathieu's ideas, but I don't think the static nature of C 
versus the dynamic nature of Javascript is any hindrance.

  -- Scott

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Extending JavaScript (C lib) mathieu.malaterre@gmail.com - 2012-07-06 00:32 -0700
  Re: Extending JavaScript (C lib) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-07-06 07:57 +0000
    Re: Extending JavaScript (C lib) "Scott Sauyet" <3103invalid@webnews.fastusenet.org> - 2012-07-06 12:05 +0000
      Re: Extending JavaScript (C lib) Stefan Weiss <krewecherl@gmail.com> - 2012-07-06 15:05 +0200
  Re: Extending JavaScript (C lib) "Scott Sauyet" <3103invalid@webnews.fastusenet.org> - 2012-07-06 12:31 +0000
    Re: Extending JavaScript (C lib) mathieu.malaterre@gmail.com - 2012-07-06 06:30 -0700
      Re: Extending JavaScript (C lib) "Scott Sauyet" <3103invalid@webnews.fastusenet.org> - 2012-07-06 14:36 +0000
      Re: Extending JavaScript (C lib) "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-07-06 11:12 -0700
  Re: Extending JavaScript (C lib) Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-07-09 11:37 +0200

csiph-web