Script language for c++ project

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
coderaider249
Posts: 9
Joined: Fri Nov 04, 2011 4:38 pm

Script language for c++ project

Post by coderaider249 »

Hi, it's a Irrnoob here. can someone explain me how can I setup javascript(or some other language) as the scripting language to do the ingame stuff for a c++ based game.
I really have no Idea!.. :?
thank you! :)
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Re: Script language for c++ project

Post by Radikalizm »

Scripting languages have nothing to do with irrlicht directly, but I'll try to help you out; this is considered a somewhat more advanced topic, so try to stick with me here :D

The main component you'll need is an interpreter for the language you're trying to integrate, google has a good open source implementation for javascript/ECMAScript called V8 (credits to serengeor for pointing this one out to me a couple of days ago), you can find it here: http://code.google.com/p/v8/
Some other popular alternatives are Lua (http://www.lua.org), Python (http://www.python.org), Squirrel (http://www.squirrel-lang.org) and lots lots more

The interpreter will provide you with an API to work with in your C/C++ application in most cases, and it should be guaranteed that it has the ability to read in source code in some way, and that it can output and run the bytecode generated from this source code in some way

What you want to do now is create a binding which functions in two directions, ie. calling native code from your scripts, and calling script code from native code; how to design this binding is dependent on the interpreter and language you're using, so that's something you'll have to figure out by yourself by reading documentation on the interpreter and the language, and possibly by going through tutorials
There are also tools like SWIG which can create parts of these bindings for you, but which also require some overhead in the form of an additional pre-processing step while building your application, and in the form of you having to write interface files for the native code you want to expose to the scripting language
For my large projects which require scripting I try to avoid SWIG because of this (and some other reasons), but for smaller projects which require a quick and dirty scripting implementation this should work fine

I hope this is of some help to you :)

EDIT:
Something I forgot to mention is that there are some pre-built bindings already available for use in C/C++ which you can use, but you'll have to see for yourself whether these are suited for the project you're doing, and if they provide all the functionality you need
I don't know any of these for Javascript, but I haven't really looked into it tbh
coderaider249
Posts: 9
Joined: Fri Nov 04, 2011 4:38 pm

Re: Script language for c++ project

Post by coderaider249 »

thanks for making things clear!. :)
Post Reply