Page 1 of 3

Embedding a scripting language in OGRE - too many choices!

Posted: Wed May 16, 2007 7:39 am
by voxel
I'm ready to embed a scripting language into my OGRE engine/games to allow for more flexibility, but I'm dazzled by the array of choices.

I'm sticking to C++ as the core language but want to read in script files for AI and scene construction so this scripting language will need some binding to OGRE and non-OGRE C++ classes. So far my choices are:

Python / PyPy
Lua / Luabind / toLua
Angelscript
Squirrel / SQPlus

Python-Ogre looks great, but it appears to be for people who use Python as their primary language. I prefer the Python language (due to history) over the other choices, but not if I have to given up the framework / integration advantages of C++.

I'm siding towards toLua++ from what I've read. Am I heading in the right direction?

Posted: Wed May 16, 2007 7:50 am
by nebukadnezzar
i'm sticking with boost::python...

and since boost 1.34 it's just more easy to embed it in your software....

Posted: Wed May 16, 2007 8:23 am
by Ajare
You might want to look at Game Monkey script. It's definitely not for beginners, but it is very quick and works exactly how you'd expect a proper scripting language to. I say "not for beginners" because binding it is complex and the community is small, but it's a very good choice for heavy-duty scripting. It's also open-source, and the language itself is quite C-like.

Posted: Wed May 16, 2007 8:34 am
by Lacero
I like lua, but I understand it a lot more than I understand any of the C++ bindings available so I write my own. I don't know how good toLua or Luabind are, but lua itself is a very solid well supported language.

Though if you already know python then boost::python might be worth trying. The quality of boost code is amazing.

Posted: Wed May 16, 2007 10:44 am
by Devil N
I've already made up my mind to use Lua as a scripting language for my next project. It's a nice small language with lots of flexibility and quite a lot of power under the hood. I've considered Game Monkey script, because it seems to be on par with Lua in many respects, but Lua just looks more solid to me.

My main objective here is to make the scripting interface as simple as possible, so even programmers with little experience will be able to write some game logic. Lua's clean and simple syntax helps in that respect. This is also why I won't bother with any of Lua's derivatives such as LuaBind or toLua; they only make the scripting portion more complicated.

There's just a couple of niggles with Lua that I'm still wrestling with, mostly concerning data transfer between Lua and C++. Small data structures such as Vectors can reasonably be passed by value, while for complicated C++ classes it makes more sense to give Lua only a pointer and to let every operation go through the C++ code. It's the middle sized data structures (aggregates of several small data structures) that I'm not sure how to handle though. Passing them by value gets pretty expensive, but giving Lua only a pointer to a structure that can be queried through C++, that seems a bit convoluted in this case.

Actually, this isn't really a Lua-specific problem, it's something that applies to any scripting language when interacting with native code. It mostly comes down to making design choices, and my indecisiveness in this case is mostly because I haven't found any good examples to work from.

Posted: Wed May 16, 2007 12:35 pm
by SpaceDude
Over the last year I've become a big fan of Python. Its great for writing small programs for doing jobs like file processing, calculations, etc... And it has a massive library of tools that makes it perfect for that. But I wouldn't generally recommend embedding it into a game. Having a massive standard library is not really a good thing when it comes to embedding because it means you need to include tons of files which will make your game much bigger than it needs to be. And when it comes to game scripting you probably don't want to allow your scripts to make use of this functionality. E.g. somebody could quite easily write a python plugin script which would gather sensitive information from the hard disc and upload somewhere on the internet.

I've only programmed in lua briefly while writing some World of Warcraft plugins. It is a much thinner layer than Python and is designed specifically for embedding in other programs (if I'm not wrong). Considering how well WoW has done, and that they use it as their scripting language. You can't really go too far wrong.

There is a good comparison between the two here:
http://lua-users.org/wiki/LuaVersusPython

Posted: Wed May 16, 2007 12:52 pm
by nebukadnezzar
you just need the python.dll - and that's not much ...

so you don't have to ship all the librarys

but then you haven't got the batteries included

Posted: Wed May 16, 2007 12:57 pm
by SpaceDude
nebukadnezzar wrote:you just need the python.dll - and that's not much ...
Oh really? I was under the impression that you would at least need to include some of the core python modules like sys, os, etc... Or are they built into the python.dll file?

Posted: Wed May 16, 2007 1:00 pm
by nebukadnezzar
no they are not...

but unless you don't need the you don't have to ship them

Posted: Wed May 16, 2007 2:15 pm
by Lord LoriK
I'm not really experienced in this subject. I've read many times about how good Lua is. I've found lots of reviews about AngelScript, Squirrel, Python, Pawn (or Small, as it was previously called), MonkeyScript, and many others, too. But I've never managed to get a good comparison based on speed. I need a lightweight script, flexible enough to customize an online game and yet fast enough so I don't need to code everything in C++.

Considering Pawn can be JIT-compiled I think it might be the fastest of those I mentioned. The problem is to bind it to C++ classes, as it's a non-OO language. Wrapping seems easy but tedious.

Are there good alternatives? What about your experience?

Posted: Wed May 16, 2007 2:26 pm
by Okdano
My choice was Lua for simplicity and because theres a lot of documentation. I used toLua++ to integrate the script into my engine.
I red a scprit languges overview in Game Programming Gems 6 and maybe you will find this article interesting.

The option depends on your needs but Lua is good enough as game script language.

Posted: Wed May 16, 2007 2:33 pm
by Project5
@voxel: I've used Lua with Luabind, Squirrel with Sqplus, and then Ruby (using an approach like RubyNative to bind to c++). The biggest piece of advice I can give for choosing is to just set up a few test projects and muck about with the different languages and find the one you like more. They're all solving the same goal, but go about it in slightly different ways.

Just remember that in order to bind your system to a scripting engine, you must have a system to bind ;-) That may narrow the choices for you; for instance I'm doing a few things with destructors and deallocations that don't play well with the above three systems' garbage collection approaches, so I have to use something else.

If you plan on supporting reflection / introspection or all ready have the facilities to do so, making your own scripting language isn't out of the question either.

Hope that helps,

--Ben

Posted: Wed May 16, 2007 3:45 pm
by tx
As ive understand it, AngelScript has major issues with Ogres memory manager. But other then that. I had good experience with AngelScript.

Posted: Wed May 16, 2007 3:48 pm
by Game_Ender
tx wrote:As ive understand it, AngelScript has major issues with Ogres memory manager. But other then that. I had good experience with AngelScript.
Which is now disabled by default everywhere so those problems should go away.

Posted: Wed May 16, 2007 4:05 pm
by tx
Game_Ender wrote:
tx wrote:As ive understand it, AngelScript has major issues with Ogres memory manager. But other then that. I had good experience with AngelScript.
Which is now disabled by default everywhere so those problems should go away.
Ok missed that, haven't updated in a long while :)

Posted: Wed May 16, 2007 5:59 pm
by Kerion
I ended up writing my own simply because none of the current languages fit well in to my environment with the features and controls I want/need. Sometimes I wish I had just chosen Python via IronPython though ;)

Posted: Thu May 17, 2007 2:23 am
by JamesKilton
:(

You mention Python but not Ruby? Unfortunately there is no boost::ruby but it's quite easy to embed the ruby interpreter into your code.

Of course I'm slightly biased. I'm a huge fan of Ruby and am close to officially annoucing my project: http://rubyforge.org/projects/ogrerb

If you're looking for something fast, small, and easy to embed, you really can't go wrong with Lua. I'm personally not a fan of the language, but it is by far the easiest language to supplement a project.

Posted: Thu May 17, 2007 2:38 am
by Praetor
You could also do javascript...

Speaking of that, for unnamed reasons, no one would happen to know a timeline for when the Mozilla people are going to have tamarin fully integrated into SpiderMonkey?

Posted: Fri May 18, 2007 7:13 pm
by voxel
Thanks for all the responses.

I'm siding towards Lua (because it's so common) and play to find a tool to autogenerate C++ to Lua bindings for C++ classes I need access in Lua.

I'll upgrade to Python / GameMonkey when I need more power.

Posted: Fri May 18, 2007 7:59 pm
by Kojack
I'll upgrade to Python / GameMonkey when I need more power.
Well, Lua was used in WOW, Farcry, Painkiller, Stalker, even in the space shuttle. So it's not exactly lacking in power. :)

Posted: Fri May 18, 2007 9:33 pm
by jacmoe
The FarCry developer/scripter created the Squirrel scripting language which he uses in his own MMOG.
Squirrel was his idea of a better Lua.
I quite like that language.
Like Lua and Python married. :wink:

Posted: Mon May 21, 2007 5:24 pm
by tau
jacmoe wrote:The FarCry developer/scripter created the Squirrel scripting language which he uses in his own MMOG.
Squirrel was his idea of a better Lua.
I quite like that language.
Like Lua and Python married. :wink:
Squirrel looks good indeed, the only drawback for me is that it's 3-5 times slower then Lua... However Python is about the same speed of Squirrel... Javascript is even slower...

TorqueScript is slow as hell, but still runs OK in Tribes 2, so it's quite relative...

My point is: dont use slow scripting lang on the server side, but it's not a big deal on the client... ;)

Posted: Mon May 21, 2007 6:32 pm
by syedhs
I am currently using Lua with Luabind in my app - it is good enough for me. And I like Lua syntax, because it is actually easier to code for content-builder. And content builder is not really a programmer :wink: And make no mistake, Lua is currently the fastest (if not among the fastest) scripting language available. No need to declare a variable before use? Not a big problem for me as long as your Lua code is not big (read: > 20k).

The only catch (for me) of using Lua is to trap the runtime error of the script: took me about a few days to get it right.

Posted: Mon May 21, 2007 9:31 pm
by Kojack
No need to declare a variable before use? Not a big problem for me as long as your Lua code is not big
It's pretty easy to intercept attempts to create new variables by using a metatable on the global table.
(Local variables are trickier I'd guess, I've only seen it done for globals. But global is the default for all variables, even if in a function, so it's the most common kind for an error)

Posted: Mon May 21, 2007 9:54 pm
by Devil N
That's the only real WTF that I have with Lua - why are variables global by default, and do local variables have to be explicitly declared? There's probably a good reason why that design choice was made and I might just be ignorant here, but having global variables all over the place seems like a recipe for lots of unexpected side effects to me. Besides, a variable that's declared globally even if it is only used locally will remain in memory after it's discarded, which is a waste of memory. Sure, you can avoid these problems with clean and consistent programming and neatly using local wherever it applies, but that's probably too much to ask for the average script programmer (i.e. non-programmers).

Looking at other scripting languages, PHP for instance, there the rules on variables are the other way round. Variables are local by default, but global when explicitly specified. That looks more logical to me, but again, I might be ignorant, so if someone could shed a light on this...