Skip to main content
GameDev.net gamedev.net
🔒 Locked

Using Javascript in for scripts in C++

Started by brwarner Aug 9, 2006 at 9:16 PM 4 replies 750+ views
Original Post
brwarner
brwarner
Does anyone know how to use &#106avascript for a scripting language in C++, sorta how they used in Messanger Plus Live for scripting and possibly some tutorials??
wstoop
wstoop
Look at SpiderMonkey (http://www.mozilla.org/js/spidermonkey/). It is Mozilla's &#106avascript interpreter. It is open source, and best of all it is The standard &#106avascript/ECMAScript implementation.<br><br>It offers a lot of power and flexibility, but unfortunately, embedding it in your application is quite complex. Be sure to read the "JS Embedder's Guide" found &#111;n that page. I remember embedding SpiderMonkey in a Visual C++ 6.0 application a couple of months ago with some difficulty. Unfortunately I cannot tell you how I did it since I don't have my notes at hand. Be sure to read all the available documentation.<br><br>Also refer to the Wikipedia entry http://en.wikipedia.org/wiki/SpiderMonkey for more SpiderMonkey related information. While you're there you might also want to check out the list of other &#106avascript implementations at http://en.wikipedia.org/wiki/List_of_&#106avascript_engines <br>
MrAccident
MrAccident
I'm using SpiderMonkey for a project right now. I didn't really find it difficult to embed at all. The source comes with makefiles / projects for a number of environments, including Microsoft Visual C++, if that's what you're using. Just pop it open and hit "Build", and you wind up with a nice lib / dll to link into your project.

Once you get it into your project, doing simple things like evaluating a script and binding functions is pretty simple. Binding classes is a bit more of a pain, but it's more tedious than complicated. Check out http://users.skynet.be/saw/SpiderMonkey.htm for another good tutorial on SpiderMonkey embedding - it covers most of the basics, including a method for binding C++ classes to &#106avascript.
wstoop
wstoop
Fair enough.

All things being equal, after reading up a bit on the SpiderMonkey website, especially under the 'Scripting Resources' page, I came to the conclusion that &#106avascript/ECMAScript is a pretty good language to embed in an application.<br><br>I seem to remember a column in Dr. Dobbs a while ago where the author claimed that &#106avascript is the scripting language of the future, seeing as more people are capable of programming in &#106avascript than in any other language. His argument being that many web and graphics design students, among others, are taught &#106avascript, even though they may never use any "real" programming languages in their careers.
daerid
daerid
I would tend to agree with that. Even though it's widely regarded as a "beginning language" because anybody who starts writing HTML pages ends up learning at least basic &#106avascript, ECMAScript is incredibly powerful. True function objects with lexical closures, as well as the whole prototype concept makes for some pretty powerful capabilities.<br><br>I wonder if anybody's taken a stab at a more friendly c++/ecmascript integration library, ala Boost.Python.<br><br>Might be something to invest some time looking into.
daerid@gmail.com
MrAccident
MrAccident
Quote:
Original post by daerid
Even though it's widely regarded as a "beginning language" because anybody who starts writing HTML pages ends up learning at least basic &#106avascript, ECMAScript is incredibly powerful. True function objects with lexical closures, as well as the whole prototype concept makes for some pretty powerful capabilities.

Yes. I love &#106avascript for those features. It's really a beautiful, flexible, and powerfully expressive language; it's a shame it gets such a bum rap because its most common use is to make a pair of googly eyes follow the cursor &#111;n some crappy web page...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.