A simple question guys, what do you usually use Lua (or any scripting language) are for? I'm planning to use OGRE 3D, SDL and Lua in a project. I know about the rest of the library, but not Lua. They said it would make prototyping faster. But what do I use it for? I haven't had the slightest thought.
So I want to ask you guys (especially the ones experienced in Lua), what do you usually use Lua for?
Err, sorry. Wrong place. I actually wanted to put this in the Game Programming area. Can the mod move this post there, please? Thanks.
When you create a sort of library for your program (functions, classes, etc.) and finally get around to using them. Sometimes that usage code is better to relay to a scripting language. Unless you and others plan on using it extensively it's probably not worth the effort though. It all depends (the necessity to switch (time/effort), length/importance of project, your experience with a side-by-side scripting language, chosen language (Lua), etc.) For example, I'm coding my library/programs with C++0x lambda branch, which simplifies a lot of code (syntax, libraries, lambda, auto, variadic, rvalues, etc). I can't imagine hitting the time/effort point to switch to Lua or Python in the near future. It just delays the sometimes inevitable though. If you know it's a big project that you'll be working on for years (that isn't a pure library project - ie boost/curl/etc - it has to be a project with lots of implementation), you might as well plan out some sort of scripting system and save yourself some time/effort. If the project has a simple completion date, you need not bother.
It's just good for simplification, run-time debugging, group collaboration/distribution (editing scripts). It also helps abstract your interface incase you need to change something (you could even switch languages/libraries without having to change your Lua scripts) or there's a bug, etc.
Examples would be configuration (for anything), game objects, game quests, player info, model info, dialog, logic (character disposition), world editors (u think GM's want to use C++? or we want them touching it), interfaces (GUI), etc. Everytime you see a code interface for anything related to the program's purpose, it *might* be quicker/easier to code that logic into a scripting language, leveraging your C++.
I've been using Lua for awhile now and it is both simple to support and simple to code in. Performance is good enough for retail games to use it as well. Lua is used in The Witcher, Neverwinter nights, etc. The Witcher is actually using a modified version of NW2 so it's no surprise it uses it.
I've integrated Lua into my home projects with little effort. There are also some very good books available for it which may make the difference between a company accepting your proposal to use it or not accepting it. There are many good third party plugins for Lua that range from reading in XML to sharing and extending C++ classes. It is not the only solution out there though.
Boost::Python also is fairly simple to integrate into existing C++. I do not know enough about it to give it a fair treatment but it is worth mentioning.
Regardless of what language you use the biggest thing to remember is that bad scripts can bring good games to their knees. Be very careful how much logic you put into said scripts. As well some people approach their usage like it's C++ or an extension of the game engine or rendering engine. This is not true and will lead to big time spaghetti code. If you put all the functions you normally would have in C++ in your script you have now effectively tied the script to the engine. This is not all that bad but if the script and/or game have intimate knowledge of each other you could very well tie the engine into the script which is very bad IMO. So before you begin figure out your interfaces between C++ and your chosen script language. As you code to the interface you will find the need for new functionality, etc.
Not to mention the largest game out there... WoW.
Originally Posted by Bubba
@All: Thank you very much. I now have a pretty good idea of what to do. BTW, does anybody know a good online tutorial on Lua out there? Thanks again.