What's GLUEscript?

GLUEscript (Glueing Libraries Using EcmaScript) is the successor of wxJavaScript. The new name covers the goal of this project: create a JavaScript engine which can be used as a general purpose language (like Perl for instance).

Read the history behind GLUEscript.

GLUEscript is developed by Franky Braem

SpiderMonkey

GLUEscript uses SpiderMonkey, the JavaScript engine used in FireFox.

SpiderMonkey

Portable Code

GLUEscript is written in portable C++ code. GLUEscript uses PoCo, a library for writing portable C++ code. And wxWidgets is used as GUI toolset. The GUI glue is optional.

Powered by POCO
Built with wxWidgets

GLUEscript uses Premake for generating makefiles for gcc, project files for Visual C++, CodeLite, Code::Blocks, ... Premake can be used on Windows, Linux and MacOS.

Documentation

Use GLUEscript and json-template to generate source code

In GLUEscript there's a lot of repeated code. All ported classes have similar header and source files. To avoid this repeating work, a generator would be helpful. json-template is a template engine written in JavaScript and can be used with GLUEscript. A JSON object is used to store data that is needed in the template.

History

It all started several years ago when I was developing a new insurance application in Java and did some research in rule engines. Instead of using a real rule engine, I was also looking at scripting languages for this purpose. When playing with Rhino, I discovered SpiderMonkey. The application was never delivered.

Because C++, and not Java, was my first love, I developed applications in C++ after work. I was also looking for a replacement of MFC and found wxWidgets. I saw that several bindings existed for scripting languages like Python, Ruby, Perl, ... And that gave me the idea to use SpiderMonkey to port wxWidgets to JavaScript. In 2002 I started the wxJavaScript project on Sourceforge and this resulted in a first release on november 2002.

After a break in 2004 and 2005, I restarted the development of wxJavaScript at the end of 2005. The focus of the project was expanded: not only wxWidgets was ported, but also MySQL, SQLite, cURL, ... At that time JavaScript on the server gained more talk on the web and that resulted in an Apache Module for wxJavaScript: mod_wxjs. The existance of this Apache module was noticed by Sitepoint.

At the end of 2008 some users mentioned that a new name for the project could get more attention to the project. Several suggestions were made and I decided to rename wxJavaScript into GLUEscript. GLUE stands for Glueing Libraries Using EcmaScript.

wxWidgets announced the end of support for wxODBC and that was the start for looking for a replacement. That was the time I discovered POCO. POCO has a lot of great libraries and I deciced to port the old wxJavaScript code to use POCO as much as possible. This gave me also the opportunity to release GLUEscript that doesn't depend on wxWidgets libraries (which was asked by some users of wxJavaScript). Now wxWidgets is only needed when you want to write GUI applications in JavaScript. A first binary download of GLUEscript was released in may 2009.

When I mentioned this release on the POCO forum, Aleksandar Fabijanic (Alex) asked me if I wasn't interested to become a contributor to POCO and write a Script environment for JavaScript/SpiderMonkey. I did, and I started developing this environment. While working on this, I started to like the coding standards of POCO and decided to use them also for GLUEscript.

Why are there so many C++ macro's in GLUEscript?

GLUEscript uses a lot of macro's in the source code. While many developers find macro's evil, I find them useful for GLUEscript for the following reasons:

  • They reduce a lot of repeating code
  • They hide difficult to read code
  • When something changes only the macro needs to be changed

The third reason is the most important reason for me: Between two versions of GLUEscript the prototype of a callback was changed. Instead of searching and replacing all code in the source files, I only needed to change the macro of the callback.

The last reason of using macro's is that I have a dream, that one day I write a parser that automatically translates C/C++ code into GLUEscript code. Parsing the syntax of macro's is easier then parsing C/C++ code.

How to configure Apache?

The apache module uses a modified version of the Apache Connector from the POCO framework. Configure this as follows:

LoadModule poco_module c:/glue/bin/mod_poco.dll
AddPocoRequestHandler GLUERequestHandlerFactory c:/glue/bin/glue_apache.dll <path>
AddHandler glue .js

All JavaScript files in path are handled by GLUEscript.

A sample: using cURL, e4x and wxWidgets to view an RSS feed

This sample will show the RSS feed of this website. For this we need:

  • cURL is used for retrieving the RSS feed
  • E4X is used to parse the XML retrieved from the RSS feed
  • wxWidgets is used for showing the RSS feed in a HTMLWindow

First we load the glues we need:

var curl = require("curl");
var wx = require("wx");

Then we initialize E4X:

XML.ignoreComments = true;
XML.ignoreWhitespace = true;
XML.prettyPrinting = false;
XML.prettyIndent = 0;

A function is created to load the RSS feed with cURL:

Syndicate content