views:

370

answers:

9

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.

A: 

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.

Pesto
+1  A: 

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

Curt Sampson
+2  A: 

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
geowa4
+5  A: 

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.

Jim Ferrans
Isn't Rhino even a standard part of modern Javas? I think it has been in J2SE since version 6.
Jörg W Mittag
That would be cool ... I embedded Rhino into a VoiceXML web browser I wrote in Java 1.2, but that was back in 2000. Rhino worked like a champ, and the browser now takes over a million calls per day (using a much more recent Rhino version).
Jim Ferrans
+3  A: 

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.

Dour High Arch
I've used Mozilla's SpiderMonkey (used in Firefox) before. It's also in JSDB (http://www.jsdb.org)
Jason S
A: 

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.

KeyserSoze
+1  A: 

Lua - everything you want and more in ~100KB

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

majkinetor
"Classes, including public/private members" are not present in Lua although you can hack this in more or less.
Nick
+1  A: 

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).

Stephen P. in Roswell
+2  A: 

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

artificialidiot