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.

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.

An example: this is a JSON object that defines RawSocket:

var native = {
               module : 'Net',
               name : 'RawSocket',
               priv : 'Poco::Net::RawSocket',
               inc : '<Poco/Net/RawSocket.h>',
               ctor : true,
               properties : [
                              { name : 'broadcast', type: 'Integer', readonly : true }
                            ],
               methods : [
                           'bind',
                           'connect',
                           'receiveBytes',
                           'receiveFrom',
                           'sendBytes',
                           'sendTo'
                         ]
             };

The template to generate the header file looks like this:

/*
 * GLUEscript - {name}Class.h
 *
 * Copyright (c) 2002-2010 Franky Braem and the GLUEscript project
 *
 * Project Info: http://gluescript.sourceforge.net
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA.
 *
 * $Id$
 */
#ifndef _GLUE_Net_{name}Class_h
#define _GLUE_Net_{name}Class_h

#include {inc}

#include <Poco/Script/JavaScript/SpiderMonkey/NativeClass.h>
using namespace Poco::Script::JavaScript::SpiderMonkey;

namespace GLUE
{
namespace {module}
{

  class {name}Class : public NativeClass<{name}Class, {priv}, 0>
  {
  public:
    GLUE_IMPL_NATIVE_CTOR({name}Class)

{.section ctor}
    GLUE_DECLARE_CTOR({priv})
{.end}

{.section properties}
    GLUE_DECLARE_PROPERTY_MAP()
    GLUE_DECLARE_GET_PROPERTY({priv})
    GLUE_DECLARE_SET_PROPERTY({priv})
    enum
    {
{.repeated section @}
       P_{name|upper}{.alternates with},
{.end}
    
    };
      
{.end}

{.section methods}
    GLUE_DECLARE_METHOD_MAP()
{.repeated section @}
    GLUE_DECLARE_METHOD({@})
{.end}
{.end}

{.section classMethods}
    GLUE_DECLARE_CLASS_METHOD_MAP()
{.repeated section @}
    GLUE_DECLARE_CLASS_METHOD({@})
{.end}
{.end}
  };

} } // Namespace GLUE::{module}

To generate the header file the following JavaScript code is used:

var system = require("system");
var templateScript = include("json-template.js");

var clazz = include(argv[0]).native;
myFormatters = function(str)
{
  if ( str == "lower" )
  {
    return function(s) { return s.toLowerCase(); }
  }
  else if ( str == "upper" )
  {
    return function(s) { return s.toUpperCase(); }
  }
  return null;
};

function execute()
{
  var headerTemplateFile = new system.TextInputStream("c:\\development\\gluescript\\utils\\header.tpl");

  var header = '';

  while(! headerTemplateFile.eof )
  {
    var line = headerTemplateFile.readLine();
    header += line;
    header += "\n";
  }

  try
  {
    var template = new templateScript.jsontemplate.Template(header, { more_formatters : myFormatters }); 
    var string = template.expand(clazz); 

    ...
  }
  catch(e)
  {
    print(e.message, "\n");
  }
  ...
}
...