Jump to content
  • Advertisement
Sign in to follow this  
brwarner

Using Javascript in for scripts in C++

This topic is 4354 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone know how to use javascript for a scripting language in C++, sorta how they used in Messanger Plus Live for scripting and possibly some tutorials??

Share this post


Link to post
Share on other sites
Advertisement
Look at SpiderMonkey (http://www.mozilla.org/js/spidermonkey/). It is Mozilla's javascript interpreter. It is open source, and best of all it is The standard javascript/ECMAScript implementation.

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

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 javascript implementations at http://en.wikipedia.org/wiki/List_of_javascript_engines

Share this post


Link to post
Share on other sites
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 javascript.

Share this post


Link to post
Share on other sites
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 javascript/ECMAScript is a pretty good language to embed in an application.

I seem to remember a column in Dr. Dobbs a while ago where the author claimed that javascript is the scripting language of the future, seeing as more people are capable of programming in javascript than in any other language. His argument being that many web and graphics design students, among others, are taught javascript, even though they may never use any "real" programming languages in their careers.

Share this post


Link to post
Share on other sites
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 javascript, ECMAScript is incredibly powerful. True function objects with lexical closures, as well as the whole prototype concept makes for some pretty powerful capabilities.

I wonder if anybody's taken a stab at a more friendly c++/ecmascript integration library, ala Boost.Python.

Might be something to invest some time looking into.

Share this post


Link to post
Share on other sites
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 javascript, 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 javascript 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 on some crappy web page...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!