From:  "sveinb" <svein.berge@gmail.com>
Date:  26 Aug 2006 20:20:12 Hong Kong Time
Newsgroup:  news.mozilla.org/netscape.public.mozilla.jseng
Subject:  

jsext

NNTP-Posting-Host:  193.216.141.182

To anyone interested in server-side JavaScript scripting: This is
another project which aims at it, and its strong point is that it makes
inclusion of C libraries stupidly simple:

C("#include ");
printf("hello, world!\n");

Yes, the above is a javascript program and printf was defined on the
fly as a native function. Any header file conforming to ANSI C should
be processable by the `C' function and therefore its functions, enums,
structs and #defines can be automatically exposed as javascript
functions, classes and properties. That means that you can access just
about any kind of library:

C("#include ");
dl("libmysql-client.so");
mysql=mysql_init(null);
conn=mysql_real_connect(mysql,"localhost","root","rootpw","mydb",null,null,0);

It is also possible to mix C code rather seamlessly into javascript for
time-critical tasks:

C(" \
double mul(double a, double b) { \
  return a*b; \
} \
");
print(mul(6,7));

You may not want the C parts to be compiled every time your program
runs, which is why it is possible to cache the compiled C code:

C("#include ","stdio.so");

The project also conains a number of modules, written in javascript,
encapsulating the C function calls in a more object-oriented fashion
which is seems more natural and convenient to a javascript programmer.
The set of modules can be expanded infinitely. Have a look at the
documentation. Try help('file') and help('os') for a start.

The lastest release of jsext can be found at:

http://sourceforge.net/projects/jsext

Thanks to Ralph Engelshall for the autoconf tarball version of
SpiderMonkey! Check it out (it's a prerequisite for jsext):

http://www.ossp.org/pkg/lib/js/

It is a bit early to start using jsext for anything serious, since it
is only in version 0.9, and will change in backwards incompatible ways.
However, if you wish to contribute, don't hesitate to sign up!

Svein Berge