Embedding a scripting language in OGRE - too many choices!
-
- Gnome
- Posts: 334
- Joined: Wed Aug 02, 2006 9:27 am
- Location: Toronto, Canada
Embedding a scripting language in OGRE - too many choices!
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?
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?
- nebukadnezzar
- Halfling
- Posts: 93
- Joined: Sun Jun 11, 2006 4:40 pm
- Location: Germany
- x 1
- Contact:
-
- Goblin
- Posts: 282
- Joined: Sat May 14, 2005 9:20 pm
- x 1
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.
-
- Halfling
- Posts: 72
- Joined: Tue Feb 13, 2007 1:57 am
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.
Though if you already know python then boost::python might be worth trying. The quality of boost code is amazing.
- Devil N
- Greenskin
- Posts: 123
- Joined: Sun Jun 26, 2005 4:32 pm
- Location: Groningen, The Netherlands
- Contact:
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.
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.
- SpaceDude
- Bronze Sponsor
- Posts: 822
- Joined: Thu Feb 02, 2006 1:49 pm
- Location: Nottingham, UK
- x 3
- Contact:
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
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
- nebukadnezzar
- Halfling
- Posts: 93
- Joined: Sun Jun 11, 2006 4:40 pm
- Location: Germany
- x 1
- Contact:
- SpaceDude
- Bronze Sponsor
- Posts: 822
- Joined: Thu Feb 02, 2006 1:49 pm
- Location: Nottingham, UK
- x 3
- Contact:
- nebukadnezzar
- Halfling
- Posts: 93
- Joined: Sun Jun 11, 2006 4:40 pm
- Location: Germany
- x 1
- Contact:
-
- Goblin
- Posts: 254
- Joined: Tue Feb 13, 2007 5:33 am
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?
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?
-
- Gnoblar
- Posts: 15
- Joined: Fri Dec 15, 2006 10:40 am
- Location: Valencia - Spain
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.
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.
- Project5
- Goblin
- Posts: 245
- Joined: Mon Nov 22, 2004 11:56 pm
- Location: New York, NY, USA
@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
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
- Game_Ender
- Ogre Magi
- Posts: 1269
- Joined: Wed May 25, 2005 2:31 am
- Location: Rockville, MD, USA
Which is now disabled by default everywhere so those problems should go away.tx wrote:As ive understand it, AngelScript has major issues with Ogres memory manager. But other then that. I had good experience with AngelScript.
Robotics @ Maryland AUV Team - Software Lead
-
- Gnoblar
- Posts: 4
- Joined: Wed May 16, 2007 3:43 pm
-
- Goblin
- Posts: 235
- Joined: Wed Feb 05, 2003 5:49 am
- Contact:
- JamesKilton
- Halfling
- Posts: 87
- Joined: Tue Jun 14, 2005 8:21 pm
- x 1
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.
- Praetor
- OGRE Retired Team Member
- Posts: 3335
- Joined: Tue Jun 21, 2005 8:26 pm
- Location: Rochester, New York, US
- x 3
- Contact:
-
- Gnome
- Posts: 334
- Joined: Wed Aug 02, 2006 9:27 am
- Location: Toronto, Canada
- jacmoe
- OGRE Retired Moderator
- Posts: 20570
- Joined: Thu Jan 22, 2004 10:13 am
- Location: Denmark
- x 179
- Contact:
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.
Squirrel was his idea of a better Lua.
I quite like that language.
Like Lua and Python married.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
- tau
- Silver Sponsor
- Posts: 413
- Joined: Wed Feb 11, 2004 11:44 am
- Location: Austin (that's kept wierd :))
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...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.
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
- syedhs
- Silver Sponsor
- Posts: 2703
- Joined: Mon Aug 29, 2005 3:24 pm
- Location: Kuala Lumpur, Malaysia
- x 51
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 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.
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.
- Kojack
- OGRE Moderator
- Posts: 7157
- Joined: Sun Jan 25, 2004 7:35 am
- Location: Brisbane, Australia
- x 534
It's pretty easy to intercept attempts to create new variables by using a metatable on the global table.No need to declare a variable before use? Not a big problem for me as long as your Lua code is not big
(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)
- Devil N
- Greenskin
- Posts: 123
- Joined: Sun Jun 26, 2005 4:32 pm
- Location: Groningen, The Netherlands
- Contact:
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...
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...