Embedding a scripting language in OGRE - too many choices!

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
voxel
Gnome
Posts: 334
Joined: Wed Aug 02, 2006 9:27 am
Location: Toronto, Canada

Embedding a scripting language in OGRE - too many choices!

Post 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?
User avatar
nebukadnezzar
Halfling
Posts: 93
Joined: Sun Jun 11, 2006 4:40 pm
Location: Germany
x 1
Contact:

Post by nebukadnezzar »

i'm sticking with boost::python...

and since boost 1.34 it's just more easy to embed it in your software....
Ajare
Goblin
Posts: 282
Joined: Sat May 14, 2005 9:20 pm
x 1

Post 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.
Lacero
Halfling
Posts: 72
Joined: Tue Feb 13, 2007 1:57 am

Post 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.
User avatar
Devil N
Greenskin
Posts: 123
Joined: Sun Jun 26, 2005 4:32 pm
Location: Groningen, The Netherlands
Contact:

Post 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.
User avatar
SpaceDude
Bronze Sponsor
Bronze Sponsor
Posts: 822
Joined: Thu Feb 02, 2006 1:49 pm
Location: Nottingham, UK
x 3
Contact:

Post 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
User avatar
nebukadnezzar
Halfling
Posts: 93
Joined: Sun Jun 11, 2006 4:40 pm
Location: Germany
x 1
Contact:

Post 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
User avatar
SpaceDude
Bronze Sponsor
Bronze Sponsor
Posts: 822
Joined: Thu Feb 02, 2006 1:49 pm
Location: Nottingham, UK
x 3
Contact:

Post 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?
User avatar
nebukadnezzar
Halfling
Posts: 93
Joined: Sun Jun 11, 2006 4:40 pm
Location: Germany
x 1
Contact:

Post by nebukadnezzar »

no they are not...

but unless you don't need the you don't have to ship them
Lord LoriK
Goblin
Posts: 254
Joined: Tue Feb 13, 2007 5:33 am

Post 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?
Okdano
Gnoblar
Posts: 15
Joined: Fri Dec 15, 2006 10:40 am
Location: Valencia - Spain

Post 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.
User avatar
Project5
Goblin
Posts: 245
Joined: Mon Nov 22, 2004 11:56 pm
Location: New York, NY, USA

Post 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
tx
Gnoblar
Posts: 4
Joined: Wed May 16, 2007 3:43 pm

Post by tx »

As ive understand it, AngelScript has major issues with Ogres memory manager. But other then that. I had good experience with AngelScript.
User avatar
Game_Ender
Ogre Magi
Posts: 1269
Joined: Wed May 25, 2005 2:31 am
Location: Rockville, MD, USA

Post 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.
tx
Gnoblar
Posts: 4
Joined: Wed May 16, 2007 3:43 pm

Post 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 :)
Kerion
Goblin
Posts: 235
Joined: Wed Feb 05, 2003 5:49 am
Contact:

Post 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 ;)
User avatar
JamesKilton
Halfling
Posts: 87
Joined: Tue Jun 14, 2005 8:21 pm
x 1

Post 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.
User avatar
Praetor
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3335
Joined: Tue Jun 21, 2005 8:26 pm
Location: Rochester, New York, US
x 3
Contact:

Post 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?
voxel
Gnome
Posts: 334
Joined: Wed Aug 02, 2006 9:27 am
Location: Toronto, Canada

Post 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.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Post 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. :)
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post 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:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
tau
Silver Sponsor
Silver Sponsor
Posts: 413
Joined: Wed Feb 11, 2004 11:44 am
Location: Austin (that's kept wierd :))

Post 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... ;)
Twitter: Tau Powered
User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2703
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 51

Post 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.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Post 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)
User avatar
Devil N
Greenskin
Posts: 123
Joined: Sun Jun 26, 2005 4:32 pm
Location: Groningen, The Netherlands
Contact:

Post 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...
Post Reply