|
|
is a standalone JavaScript development environment for using JavaScript as a general-purpose scripting language.
jslibs provides a set of native modules that contains various general purpose classes and functions.
Some of these modules are simple wrappers for familiar libraries such as : zlib, SQLite, FastCGI, NSPR (Netscape Portable Runtime) , ODE (Open Dynamics Engine) , libpng, libjpeg, OpenGL, OpenAL, LibTomCrypt, libffi (Foreign function interface) , ...
Other modules provide tools for enhancing JavaScript programming : Print(), Load(), Exec(), Seal(), Expand(), Buffer class, ...
The jslibs distribution comes with a small standalone command line access program (jshost) that can be used to run JavaScript files. Note that the modules are quite independent from jshost and can be used in any project that embeds SpiderMonkey. A Windows binary (without console) is also available (jswinhost).
jslibs is available under GNU GPL 2.0 license. You can access the source code through the Subversion repository using the 'Source' tab.
Project documentation is available in the 'Wiki' tab. In this section, you can find modules and classes API.
Feel free to ask any question or make any comments on this project in the discussion group or the mailing list.
If you would like to report a defect or request an enhancement, click the 'Issues' tab and read the existing issues. If no existing issue is relevant, you may enter a new one. You can also use the discussion group to propose new features.
jslibs is under development, so you can contact me if you want to join the project.

- 2008.04.13 - I am working on a complete OpenGL API wrapping.
- 2008.03.26 - I am working on a QA test system to ensure that there are no outstanding regressions between jslibs releases. You can try it using: ./jshost qarun.js
- 2008.03.15 - New release: DEVSNAPSHOT 2008.03.15 r 1402 (announce) (Linux 32-bit compilation).
- 2008.03.09 - Start implementation of the class jsio::SharedMemory.
- 2008.03.06 - Documentation of jsio, jscrypt, jsode are up to date.
- 2008.02.28 - A bug has been found in the jscrypt module. The fix is done and a new devsnapshot will be released soon.
- 2008.02.27 - Documentation is being updated.
- 2008.02.26 - A new devsnapshot of jslibs has been released and is available in the download section (changelog).
- 2008.02.18 - 64-bit port of jslibs is in progress.
- 2007.12.20 - New jslibs module: jsdebug (debuging tools and memory diagnostic)
- 2007.12.12 - jsnspr module has been renamed into jsio (documentation is not completely updated)
- ...

Some code snippets
Display the content of a file (module jsio)
Print( new File('test.txt').content );Compress a string (module jsz)
var compressedText = new Z(Z.DEFLATE)('This text will be compressed', true);Call MessageBoxA in User32.dll (module jsffi / jsni)
function Alert( text, caption ) {
var ret = new NativeData().PU32.Alloc();
new NativeModule('C:\\WINDOWS\\SYSTEM32\\User32').Proc('MessageBoxA')( ret, DWORD( 0 ), SZ(text), SZ( caption || 'Alert' ), DWORD( 1 ) );
return ret[0];
}One-line database query (module jssqlite)
var myDatabaseVersion = new Database('myDatabase').Exec('PRAGMA user_version');Non-blocking sockets (module jsio)
var soc = new Socket();
soc.Connect( 'localhost', 8080 );
soc.writable = function(s) {
delete soc.writable;
s.Send('GET\r\n');
}
soc.readable = function(s) {
Print( s.Recv() );
}
while(!endSignal)
Poll([soc],100);Encrypt data using blowfish (module jscrypt)
var rnd = new Prng('yarrow');
rnd.AutoEntropy(128);
var key = new Hash('sha256')('this is a secret key');
var IV = rnd(Crypt.BlockLength('blowfish'));
var crypt = new Crypt( 'ctr', 'blowfish', key, IV );
var plainText = 'secret string';
var cipherData = crypt.Encrypt(plainText);Use Open Dynamics Engine (module jsode)
var world = new World; world.gravity = [0,0,-0.81]; var body1 = new Body(world); var geo1 = new GeomBox(); geo1.body = body1; var body2 = new Body(world); var geo2 = new GeomBox(); geo2.body = body2; var joint = new JointHinge(world); joint.body1 = body1; joint.body2 = body2; joint.anchor = [4,4,0]; joint.axis = [1,0,0]; joint.loStop = 1; joint.hiStop = 1.5; body1.linearVel = [0,0,19]; body1.angularVel = [1,1,0]; ...
Load a jpeg image (module jsimage)
var texture = new Jpeg(new File('R0010235.JPG').Open(File.RDONLY)).Load().Trim([10,10,20,20]);
Print( texture.width+'x'+texture.height+'x'+texture.channels, '\n' );Mini 3D world with FPS-like controls (module jsgraphics)
LoadModule('jsstd');
LoadModule('jsio');
LoadModule('jsgraphics');
var glc = Exec('OpenGL.js'); // OpenGL constants
var vk = Exec('WindowsKeys.js'); // win keys constants
Exec('winTools.js'); // manage 'infinite' mouse displacements
var win = new Window();
var gl = new Gl(win);
gl.LoadIdentity();
var list1 = gl.StartList();
for ( let i = 0; i < 100; i++ ) {
gl.PushMatrix();
gl.Translate(Math.random()*1000-500, Math.random()*1000-500, Math.random()*1000-500 );
gl.Cube();
gl.PopMatrix();
}
gl.EndList();
var mouse = new MouseMotion(win); // defined in winTools.js
var camera = new Transformation();
camera.Product( new Transformation().Translation(-1,-1,10) );
var tx=0, ty=0, speed=1, run=0;
mouse.button = function( b, polarity, b1, b2, b3 ) {
mouse.infiniteMode = b1 || b2 || b3;
if ( b == 2 ) run = polarity ? 1 : 0;
if ( b == 3 ) speed = 1;
}
mouse.delta = function( dx,dy,dw, b1,b2,b3 ) {
if ( dw != 0 )
camera.Product(new Transformation().Translation( 0,0, -dw*10 ));
if ( b1 || b2 ) {
tx += dx; ty += dy;
camera.LoadRotation(new Transformation().RotationZ(tx/2).Product( new Transformation().RotationX(-ty/2) ));
}
}
function Render() {
var cameraPosition = new Transformation();
cameraPosition.Translation( 0, 0, -speed * run );
camera.Product(cameraPosition);
gl.Clear( glc.COLOR_BUFFER_BIT | glc.DEPTH_BUFFER_BIT );
var m = new Transformation().Load(camera).Invert();
gl.LoadMatrix(m);
gl.Color(0.5,0.5,0.5);
gl.Translate(0,0,0);
for ( var x = -100; x<100; x+=2 )
for ( var y = -100; y<100; y+=2 )
gl.Quad(x,y,x+1,y+1);
gl.LoadMatrix(m);
gl.CallList(list1);
CollectGarbage();
Sleep(1);
gl.SwapBuffers();
}
win.onidle = Render;
win.onkeydown = function( key, l ) {
if ( ket == vk.ESC )
win.Exit();
}
win.onsize = function( w, h ) {
gl.Viewport([0,0,w,h]);
gl.Perspective( 60, 0.01, 10000 );
Render();
}
gl.Init();
gl.Perspective( 60, 0.01, 10000 );
win.ProcessEvents();A configurable systray shortcut launcher (module jswinshell)
var s = new Systray();
s.icon = new Icon( 0 );
s.menu = { add:'Add', exit:'Exit', s1:{ separator:true } };
s.onmousedown = function( button ) {
s.PopupMenu();
}
s.oncommand = function( id, button ) {
switch ( id ) {
case 'exit':
return true;
case 'add':
var fileName = FileOpenDialog( 'executable files|*.exe;*.com;*.cmd;*.bat|all files|*.*' );
if ( !fileName )
return;
var icon = ExtractIcon( fileName );
var text = fileName.substr( fileName.lastIndexOf( '\\' ) + 1 );
s.menu[fileName] = { icon:icon, text:text };
break;
default:
if ( button == 1 )
CreateProcess( id );
else
if ( MessageBox( 'Remove item: ' + id + '? ', 'Question', MB.YESNO) == ID.YES )
delete s.menu[id];
}
}
do { Sleep(100) } while ( !s.ProcessEvents() );A server-side script using E4X with the FastCGI module (module jsfastcgi)
Write( "Content-type: text/html\r\n\r\n" );
function CGIVariableList() {
var fcgiParams = GetParam();
var list = <ul/>;
for ( var k in fcgiParams )
list += <li><b>{k} = </b><pre>{fcgiParams[k]}</pre></li>;
return list;
}
Write(
<html>
<head>
<title>teswt</title>
</head>
<body>
<H1>HELLO WORLD</H1>
<p>CGI/1.1 variables:</p> {CGIVariableList()}
</body>
</html>
);


