Are there any plans to add a mechanism into SpiderMonkey to let it
interact with its environment, eg accessing libraries?
I've been looking into the task of implementing a libdl bridge, which
would allow:
- loading any C library dynamically, such as libmysqlclient, libc etc
- passing opaque pointers to and from javascript code
- javascript code to access C data structures, including
dereferencing pointers, pulling out native typed items etc
- javascript code to set up C call frames and invoke C functions
- javascript code to create/populate C data structures
Such a mechanism would allow people to write wrappers in
pure javascript to interact with any C library on the system, and
ultimately allow Spidermonkey to be used to power websites written in
server-side javascript.
This would have the appeal of allowing the same language to be used on
server and client side.
My question - are there any plans to move Spidermonkey in this direction,
or has anyone written anything like this?
For me, it would be quite a learning curve to accomplish all of this, and
I'd rather not re-invent the wheel.
Cheers
aum
Shanti
It is quite easy to use it, you need to checkout http://jslibs.googlecode.com/svn/trunk/libffi/ and http://jslibs.googlecode.com/svn/trunk/jsffi/
Here is an example of use ( http://jslibs.googlecode.com/svn/trunk/tests/jsni_system.js ) :
function Alert( text, caption ) {
ret = new NativeData()
ret.PU32.Alloc();
new NativeModule('User32', true ).Proc('MessageBoxA')( ret, NULL(), SZ(text), SZ( caption || 'Alert' ), INT( 0 ) ); // using ordinal value of MessageBoxA
return ret[0];
}
(give me feedback)
Franck.
> (give me feedback)
* Write some nice thorough HTML doco, sufficient for
folks to accomplish whatever they need without having
to look at the source code
* Toss in a couple of unix examples:
- using simple libc functions like sprintf
- using socket functions to build a minimal http client
Cheers
aum