I'm investigating about virtual machines and their use in Games.

I'm looking for something cross-platform (at least win/mac/linux, mobile and consoles are a nice to have but not mandatory) and it would be nice if it could be binded to the usual things that you need for a game, like a graphics and sound lib. If it had any sort of automatic garbage collection, it would be nice, too. And since I want to use it for games, it should be fast and not very memory-consuming.

So far I've found:

I'm leaving the Java Virtual Machine and .net VM out of this list since I feel they are a bit too big for my purposes - but I'm far from an expert on these things. If you think I should include them, please put your reasons below.

Am I missing any important one?

PS: I think this should be a community wiki, but I don't seem to be able to mark it as one.

EDIT: My final objective is creating a scripting language for game development. I've no problem with interpreters (have implemented a couple in the past) but this time I'd like to translate the Abstract Syntax Tree of my language to a VM, for efficiency mostly.

  • 1
    \$\begingroup\$ Two points: You might want to clarify what you want the VM for. When I hear "virtual machine" I think virtualbox, namely being able to, say, run a bunch of different OSes virtually for testing games. Obviously after reading the question I understand a little bit better, but you might want to explicitly call it out as a scripting back end. \$\endgroup\$ – Tetrad Jan 24 '11 at 9:03
  • \$\begingroup\$ Also, these kinds of questions are expressly frowned upon in the FAQ: "your answer is provided along with the question, and you expect more answers: “I use ______ for ______, what do you use?”". Do you have a specific problem with specific requirements that you need a VM for? \$\endgroup\$ – Tetrad Jan 24 '11 at 9:05
  • \$\begingroup\$ @Tetrad: Thanks for your comments. I've included the problem I'm trying to solve at the end of my question. \$\endgroup\$ – egarcia Jan 24 '11 at 9:14
  • \$\begingroup\$ When I hear Virtual Machine in the gaming world I think of game engines. A well written non-typed engine is pretty much a virtual machine for games. And if one is written to support all the different platforms... well you can see where I am going with this.. One of the best Gaming Virtual Machines? Unreal.. I have seen so many different types of games come out citing their technology its becoming annoying :) \$\endgroup\$ – James Jan 24 '11 at 17:40

If you are looking for something to embed, Lua or Python are probably your best bet. Python is an easier language to work in than Lua, but Lua is the better choice for ease of embedding (we just did both and use them for different tasks). Also if you are concerned about speed, LuaJIT makes it so much of a non-issue your head will spin. Look at something like Luabind or SWIG to help expose C/C++ to the script environment.


"Game oriented virtual machines" have been around just about as long as there has been games. Zork, and other Infocom games, ran on Z-Machine. Whenever the company got the Z-Machine ported onto a new platform (say, c-64), they could easily release their whole portfolio on said platform.

Later on, companies like Sierra or LucasArts came up with their own (AGI, SCI, SCUMM).

Those were, however, extremely limited scope VMs for games (interactive fiction in case of infocom and graphic adventure in case of Sierra or LucasArts).

So what's needed for a game anyway? Steve Wozniak was quoted to say that when he was designing the apple, (or possibly apple II?) he pondered what features a game needs - and the computer was never primarily a game platform. So looking for a VM that aims JUST games seems kind of funny, unless you're targeting some extremely specific game genre.

As such, the most distributed VMs out there today that are used for games are, I guess, java vm and flash vm.

  • \$\begingroup\$ Your answer was very rich, thank you. I think I need something a bit less on the extremes: more current than SCUMM or AGI but more efficient than the jvm. \$\endgroup\$ – egarcia Jan 24 '11 at 23:57

If you can get a copy, Game Scripting Mastery is a great book for exactly what you want. It goes through the design and implementation of a scripting language for a game, covering everything you need to know.

It goes from the general reasons to use a scripting language, to writing the virtual machine and bytecode, and writing a parser and lexer.

Of course, it covers a lot more than you want for this question, but I think it would fit perfectly with your current project, if you can afford a copy. ;-)

EDIT: This isn't exactly what you're wanting, since you're looking for an out-of-the-box solution. However, if you're interested in rolling your own, it is a great resource. And not skimpy (1250 pages).

  • \$\begingroup\$ Thanks for the reference. For interpreter implementation I can only recommend any of the antlr books by Terrence Parr. I might give this a try, if I can get hold of a used version (The new one is just prohibitive ... 400 bucks wow) \$\endgroup\$ – egarcia Jan 24 '11 at 23:33
  • \$\begingroup\$ My opinion of that book comes from skimming it once in a bookstore, but it looked absolutely terrible. It was comprehensive, but comprehensively terrible. The Dragon Book is probably still best if you want to learn to write your own; if you want to make a stack-focused language instead, pick up any of the free Forth books online. \$\endgroup\$ – user744 Jan 25 '11 at 17:58
  • \$\begingroup\$ The Dragon Book is outdated IMHO. It concentrates on details you shouldn't be caring about on the XXIst century. ANTLR, and its associated books, is a great improvement and I can't recommend it enough. \$\endgroup\$ – egarcia Jan 31 '11 at 10:50
  • \$\begingroup\$ @egarcia, I do not think the Dragon Book is outdated. I've flicked through, and it may not be the optimum solution nowadays, with ANTLR and the likes around, but it certainly covers its material very well. And The Game Scripting Mastery is certainly the simplest/clearest I've seen, if the code quality leaves a lot to be desired (i.e. 2 full pages of if(token type) print error; ) \$\endgroup\$ – The Communist Duck Jan 31 '11 at 16:10
  • \$\begingroup\$ @Duck, What I meant by "outdated" was exactly that - it's not optimum nowadays. It focus on making things easy for the machine (LR-based) and not for the programmer (LL-based). On top of that, new algorithms have been discovered since its writing. Check out LL(*) - antlr.org/wiki/display/~admin/LL%28*%29+grammar+analysis \$\endgroup\$ – egarcia Jan 31 '11 at 17:41

I would put the Java VM back on your list. It has been used by enterprise programmers for over a decade, has many good libraries that do exactly what you are looking for, and is running between 85 ~ 90 % the speed of compiled native code (sometimes faster, sometimes slower, but usually close). On top of that, Java's reflection API will let you map 'script' classes into java code very easily, and you could emulate a script such as Groovy if you wanted to.

Yes, it is big, but you only need to use as much of it as you require. The Java VM (JVM) has a notion of a maximum heap size. This maximum memory imprint is set by using the -Xmx(Size)M parameter. An example of this would be:

java game.jar -Xmx512M

This would set the maximum memory heap size of the JVM to 512 MB. This link may prove to be helpful. For what it's worth, Minecraft Server usually operates fine with a heap size of 1024 MB, as detailed at the bottom of the download page.

  • \$\begingroup\$ Thanks for your feedback. Do you happen to know how much memory does it take by itself? I have no idea. \$\endgroup\$ – egarcia Jan 24 '11 at 23:28
  • \$\begingroup\$ @egarcia: Edited my answer. \$\endgroup\$ – James Jan 25 '11 at 16:49
  • \$\begingroup\$ Embedding a JVM inside something else can be exceedingly hard bordering on impossible. Unless you also intend to write the rest of the engine in Java, this isn't a good option. \$\endgroup\$ – coderanger Jan 25 '11 at 17:22
  • \$\begingroup\$ He mentions win/mac/linux as required, mobiles and consoles as possible. The JVM satisfies the requirements. \$\endgroup\$ – James Jan 25 '11 at 17:42
  • \$\begingroup\$ @coderanger: actually, there are several projects out there that compile non-java code directly to the jvm. For example, see groovy.codehaus.org \$\endgroup\$ – egarcia Jan 26 '11 at 10:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.