I want to embed Javascript in a hobby game engine of mine. Now that we have the 5th generation of Javascript engines out (all blazing fast) I'm curious what engine would you choose to embed in a C++ framework (that includes actual ease of embeding it)?
Note: Just to make it clear, I'm not interested in DOM scripting or writing Javascript in a browser.
Here's a compilation of links so far and some tips from the thread
- SpiderMonkey
- tracemonkey (note:backwards compatible with spidermonkey):
- V8
- Squirrelfish
Just for the record, I love Lua and have already embedded it in game engines about 5 times at work.
However now this is a hobby project, and I think that Javascript being known by most web developers and because its ECMA, Flash and Flex developers, a game engine that uses Javascript and XML for scripting would be more user-friendly and cater to a larger user base (and one that so far has not had a chance to use their skills for games) than one with Lua (and there are plenty of those around!).
Also for the record I'll go with V8 on this one, mostly because I like it's C++ style.
Try Javascript .NET:
http://javascriptdotnet.codeplex.com/
It implements Google V8. You can compile and run Javascript directly from .NET code with it, and supply CLI objects to be used by the Javascript code as well. And V8 is probably the best engine ever created in terms of performance, it generates native code from Javascript.
I believe that v8 only works on x86, x64 and arm processors at the moment. Which might be a disadvantage.
With regards to thread safety, from include/v8.h:
You can read more in the source file (it looks like doxygen documentation, but they don't seem to have put it up anywhere).
Update: That comment has been removed, probably some time ago. It looks like v8 now has an
Isolate
object which represents an instance of the engine. A singleIsolate
instance can only be used in a single thread at a time, but otherIsolate
instances can be used in other threads at the same time.Is Java Script really the right language for your game? Many of games out there are using the Lua programming language for scripting. It's easy to integrate, it's very small, it compiles on almost every platform and it's easy to learn.
This somewhat off topic, but thinking outside the box can be important to get things right .
The benchmark that came out when V8 first hit the scene that showed V8 being 1000% (or whatever) faster than other engines was heavily weighted towards favoring engines that were good at recursion. If your code uses a lot of recursion, then V8 might give you a significant advantage, speed-wise. For "real world" (currently, at least) web stuff, SquirrelFish Extreme seems to be the hands down winner at the moment (see my blog post on the topic for the results of my own, informal testing).
As others have pointed out, ease of integration and quality of documentation might prevail over pure speed. It don't mean jack if you don't ship!
I would keep an eye on v8 as it is screaming fast javascript engine, and i'm sure it will develop cross-platform support as it grows to maturity.
I'd wait for TraceMonkey, the next evolution of SpiderMonkey to come out. Faster and better designed. ( Uses code donated from Adobe Flash ).
Tracemonkey prides itself in making repetitious actions much faster by aggressively optimizing the structure at runtime based on actual usage, which aught to be handy for game-augmentation.