Scripting Languages, write your own or use Python?

Started by
9 comments, last by RFLAGG 19 years, 7 months ago
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.
Advertisement
boost.python and pyste make it relatively easy in C++

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]
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++?
lua rocks so very hard.

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

lua.org
Yeah, I'd go with Lua instead of Python.
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
-LuctusIn the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move - Douglas Adams
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.
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]
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.
You can also try &#106avascript, <a href="http://www.mozilla.org/js">www.mozilla.org/js</a>. The advantage is that the syntax is very similar to C/Java/PHP, which many scripters will know. &#106avascript 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.

This topic is closed to new replies.

Advertisement