Question

I am looking for an ECMAScript alternative to work as a scripting language for custom application logic. There are things I like about ECMA, especially the syntax for the newer spec(like AS3).

Unfortunately, the AS3 engine is not open source to be able to integrate in a project. I would like a scripting language that was designed for object oriented use.

Specifically, is there a language that has:

  • Statically typed variables(optional)
  • Classes, including public/private members
  • Inheritance, including Interfaces
  • Packages(optional)
  • Clean syntax
  • Must be able to interface as an internal scripting language for an application(like Javascript for a browser), can not be an external system call.

Things I would rather do without

  • The messy ECMA prototype object

What languages that you know about fit this profile? I've had difficulty finding a quality scripting language that was designed for good object oriented design.

Was it helpful?

Solution

In Java the best ECMAScript (Javascript) option is to embed Rhino. I don't find the prototype-based inheritance a deal killer, as with a bit of discipline you can make it behave almost like class-based inheritance.

If you want something that interoperates very closely with Java, go with Groovy. If you need JVM compatibility, also look into Jython (python on the JVM), Jruby (Ruby on the JVM) and Scala (a functional language on the JVM). If you don't care about Java and JVM compatibility, look at Ruby, Python, and Erlang. Clojure is a dialect of Lisp on the JVM.

Going further afield, TCL (Tool Command Language) lets you embed an interpreter in C/C++ code, there are many embeddable Lisp and Scheme interpreters, etc.

OTHER TIPS

If you want a scripting language that works like ECMAScript, why not use ECMAScript? There are many Open Source implementations, just take a look at the list on Wikipedia.

I'd recommend either Python or Ruby. Neither are like ECMA, but I learned them after JavaScript, and they were a snap to pick up. Plus, they are more powerful languages, making it a better alternative to using a JavaScript engine inside of your application (Rhino for Java).

Python

  • Forces clean syntax (almost like English while is not False:)
  • Multiple inheritance (no interfaces)
  • Interpreter can be extended using C/C++ (possibly used for your adapters, if needed)

Ruby

  • Syntax is supposed to be close to English (unless conditional, until loop)
  • Everything is an object
  • Only supports single inheritance, but uses Mixins to add functionality

Both

  • Classes
  • Can be embedded in another application
  • Private members
  • Packages

Lua - everything you want and more in ~100KB

See this page for comparison betwen Lua and other mentioned languages.

Haxe on Neko looks like the exact thing you want. I don't know how embeddable nekovm is, but it is opensource so you can fiddle with it. http://haxe.org

The Ruby interpreter can also be embedded within C programs, and may be considered by some to be more object-oriented than Python.

We use ECMAscript as an extension language for the software product I work on and it works quite well. Being a standard (and popular) language, it's nice to be able to point our users to the copious off the shelf documentation for the language. We built our own ECMAscript compiler that translates into bytecode for the platform we are running on, but if I had it to do over again, I'd seriously consider embedding Google's V8 ECMAscript engine (in fact, I'd even consider building our entire app on it).

I'd go with something fairly mainstream to simplify things. Having read your requirements, I'd recommend Python. It doesn't really have interfaces in the Java/C# way, but it doesn't really need them, either. Other than that, it should be a good fit.

QtScript is ECMAScript. You don't mention what the main part of your application is written in, but I suppose it's not Qt, or you'd already know about QtScript.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top