Sign in to follow this  
MrRage

Scripting Languages, write your own or use Python?

Recommended Posts

I have a C++ program that I am designing right now and it needs some kind of scripting language built into each object. I don’t know how much overhead is involved here but I had two ideas of solving this problems. The first approach would be to use a series of objects that execute a command (such as +, -, if, for…) and stick them together in an array of objects. The second idea was to make an array of assembly instructions in real time and execute that based on what the scrip gave us to do – this might be a lot harder than it sounds. Last would be interfacing my objects to Python, although I have a friend that has done C -> python but we haven’t done C++ objects/namespaces to python yet. So far the objects will hold the script code, list of attributes and an input handle. The input handle will be assigned to an input device or devices (such as mouse/keyboard/internet/AI…) and if that input is triggered then the value generated (in the form of a value structure) is fed to this object. From there we execute the scrip on this value and interact with the list of attributes for this object or interact with other objects. Python is a great scripting language alternative, but I’m concerned with the steps needed to make it work well under a C++ environment.

Share this post


Link to post
Share on other sites
You could write your own Lisp/Scheme/Forth/etc. interpreter in C++ very easily. You only have to implement as much as you'd like (no need to be "standards compliant" or anything).

However, if Python provides what you need, I'd use it. I know you can write Python which calls C++ "under the hood", but can you do it the other way around, calling Python from C++?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
lua rocks so very hard.

the C/C++ interface isn't an afterthought, it was designed with it in mind.

lua.org

Share this post


Link to post
Share on other sites
Quote:
Original post by petewood
The only danger of using Python as a scripting language is that you may find yourself moving more and more things from being coded in C++ to being done in Python.[smile]

which isn't necessarily a bad thing, no?
Quote:
Original post by Russell
but can you do it the other way around, calling Python from C++?

Yep, very much possible, and extremely easy when using boost::python

Share this post


Link to post
Share on other sites
Lua, Python, Ruby, and AngelCode are all worth taking a look at. I've also heard mention of a language called Small... I haven't done enough research to recommend it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Luctus
Quote:
Original post by petewood
The only danger of using Python as a scripting language is that you may find yourself moving more and more things from being coded in C++ to being done in Python.[smile]

which isn't necessarily a bad thing, no?


[wink]

Share this post


Link to post
Share on other sites
Quote:
Original post by Russell
You could write your own Lisp/Scheme/Forth/etc. interpreter in C++ very easily.


I doubt it. :)

Use python or lua. I happen to love python, but I've heard good things about lua. Like the guy said, lua was designed with interoperability from the beginning.

Share this post


Link to post
Share on other sites
You can also try javascript, www.mozilla.org/js. The advantage is that the syntax is very similar to C/Java/PHP, which many scripters will know. javascript actually has a lot of the advantages of Python, for example the ability to pass a function around and dynamic typing where if you write ob.x it works for any object which has a field x.

Share this post


Link to post
Share on other sites
Quote:
Original post by Russell
You could write your own Lisp/Scheme/Forth/etc. interpreter in C++ very easily. You only have to implement as much as you'd like (no need to be "standards compliant" or anything).

However, if Python provides what you need, I'd use it. I know you can write Python which calls C++ "under the hood", but can you do it the other way around, calling Python from C++?

If you want speed, then you don't want to use an interpreter. Use a virual machine, like lua does. (I prefer lua over python myself, for no *real* reason..)

lua is super easy to work with, and there are tutorials on gamedev for it that are nice (although documentation else-were is somewhat... hairy..)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this