SpiderMonkey for Games?
I have been doing some research on scripting languages, trying to find one best for my needs and one that has a syntex I like. My favorite is javascript so after doing some searching for C++ javascript parser, I came across spidermonkey. My question is: would it be practical for a game (ie. speed, flexability, etc).
Also, with lua, you can bind classes and vars your self or use one of the many tools such as tolua or luabind. Is this the same with spidermonkey?
Last but not least, what other free c++ javascript parsers are there?
www.jinx.com www.thebroken.org www.suprnova.org www.mozilla.org
I'm using SpiderMonkey for a simple game (jsInvaders) and the speed is quite acceptable. As for flexibility, the biggest issue I've had was that I've had to create my own container/linked list type class in javascript to hold my game objects.
Embedding it is fairly simple and binding your classes is fairly easy, however there's no automated utilities to help you with the binding. It's my intention to get round to creating some support utilities for SpiderMonkey to simplfy the bindings even more. I find SpiderMonkey easier to use than Lua, simply because you don't have to worry about messing around with the stack. There are some annoying 'features' that aren't documented anywhere, but you can easily overcome them if you know what they are.
I've found SpiderMonkey to be excellent when it comes to event callback type functions (eg: the game calls the script at a certain event's occurrence). I haven't used it in a 'thread' like manner, but the SM engine can support multiple contexts at once, so I doubt it'd be a problem.
As for free parsers, I'm not really aware of any except SpiderMonkey. There is DMDScript by DigitalMars, but the author is unwilling to release an API to use the library without payment (I emailed him).
The one biggest drawback I have found with SpiderMonkey is the lack of documentation and tutorials when it comes to embedding it. With that in mind, I'm writing an article series for gamedev and part 2 goes over how to set up a basic spidermonkey environment within a game.
Have a play with it, if you don't like it there's plenty of other libraries out there to use ;) If you need a hand, feel free to email me or drop me a message.
Embedding it is fairly simple and binding your classes is fairly easy, however there's no automated utilities to help you with the binding. It's my intention to get round to creating some support utilities for SpiderMonkey to simplfy the bindings even more. I find SpiderMonkey easier to use than Lua, simply because you don't have to worry about messing around with the stack. There are some annoying 'features' that aren't documented anywhere, but you can easily overcome them if you know what they are.
I've found SpiderMonkey to be excellent when it comes to event callback type functions (eg: the game calls the script at a certain event's occurrence). I haven't used it in a 'thread' like manner, but the SM engine can support multiple contexts at once, so I doubt it'd be a problem.
As for free parsers, I'm not really aware of any except SpiderMonkey. There is DMDScript by DigitalMars, but the author is unwilling to release an API to use the library without payment (I emailed him).
The one biggest drawback I have found with SpiderMonkey is the lack of documentation and tutorials when it comes to embedding it. With that in mind, I'm writing an article series for gamedev and part 2 goes over how to set up a basic spidermonkey environment within a game.
Have a play with it, if you don't like it there's plenty of other libraries out there to use ;) If you need a hand, feel free to email me or drop me a message.
There is another open source javascript interpreter NJS which seems to have stalled.
Spidermonkey would generally be my preferred one.
Of course we have luabind... but I think someone has made something similar for Spidermonkey, but it could be a bit ropey.
Mark
Spidermonkey would generally be my preferred one.
Of course we have luabind... but I think someone has made something similar for Spidermonkey, but it could be a bit ropey.
Mark
I was going to reply sooner, but I havent had the chance. Anyway, thanks guys for your comments. Oli, Im going to send you a pm. Thanks again.
www.jinx.com www.thebroken.org www.suprnova.org www.mozilla.org
0AD (an RTS game) is using SpiderMonkey for scripting, and I think it's working out well for them. You can also see how it's being used in the Mozilla source code, probably.
Also, you shouldn't be worrying too much about scripting performance. Scripting should only cover high-level logic that is invoked fairly infrequently. If you're running so many scripts per frame that performance is an issue, you're not using it for the right purpose.
Also, you shouldn't be worrying too much about scripting performance. Scripting should only cover high-level logic that is invoked fairly infrequently. If you're running so many scripts per frame that performance is an issue, you're not using it for the right purpose.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement