C++ w/ Lua

Learning C++ w/ Lua isn't too difficult I find, but my main problem is trying to find a good use for scripting in my program. I'm working on a top-down 2D RPG using SFML for Graphics and Event handling. I was told to use Lua to load maps and design AI, but I don't understand how that would be done.

Does anyone know of any books that teach C++ w/ Lua with examples (preferably game oriented examples)?
closed account (o1vk4iN6)
How are you using Lua ? I wouldn't be using it to make the core of the game. The only thing I would use Lua for is specific game stuff (not transferable between games) ie, cutscenes. Even than I would prefer an object-oriented language and have C-like syntax like squirrel ( http://en.wikipedia.org/wiki/Squirrel_(programming_language) ).
Last edited on
I was going to use it as a configuration file for things (the game, each map, each NPC, etc). However, I couldn't find anything that could be configured in the file. The only things I could think of was names, and filepaths to specific images. Haha.
Could you post your C++ with lua? I assume its lua 5.2 you're using, I'm attempting to do the same but all the tutorials seem to be for 5.0 or 5.1, and things have been renamed.

you could use lua to implement weapons, items, equipment, enemies, tilesets, etc.
See: http://www.cplusplus.com/forum/general/75803/

Basically, what you do is have the main engine written in C++. The engine takes care of such things as managing resources (memory, CPU time, threads, files, etc.), loading game assets, rendering graphics, and so on. Then you write the actual game in Lua, which uses the engine as a library of sorts.
The main advantage of this is that, as I said in that thread, recompiling a project every time you make a change is unreasonable in such a dynamic codebase as a game. The engine doesn't change as fast because most of its code is fairly boilerplate; there aren't that many ways to write, say, an object manager. The main game is subject to constant change because of gameplay tweaks and the like.
That link doesn't really explain things, and I understand the concept, but not the code, coding in Lua is piss easy compared to C++ so that isn't an issue either (although they lack pre/postfix incrementers, and a ternary operator D: !) I have the lua module and .dll ready to compile into my program, I just don't know how to accomplish it, although I haven't looked at the official documentation yet.
@helios: I understand why we use it and how to program in it (it being Lua), but what I don't understand is what actually to write in the script. I can't figure out, say to implement a weapon, what kind of information that I need to script into Lua to be put into C++. I can't really find much except for names and a few stats (but that's just setting variable values). I assume there is something that I need to use Lua functions for.

I guess what I'm trying to say is, when do I use Lua functions to perform a task as opposed to C++ functions? Should I just write the entire Weapon class in Lua? Haha
Should I just write the entire Weapon class in Lua?
Basically. Yes.
You write the entire high level logic of the game in Lua and leave the low level stuff to C++.

For example, if you were to make a Pacman, Lua would control the animations (i.e. which image should be displayed next), the items (the effects of picking up an item), the ghosts' AI, the control scheme, and the scoring system, while C++ would control the file system, the input device, graphics rendering, and audio playback (that is, not deciding what music or sound effect to play, but actually sending audio to the speakers).
OH! Okay! That is the answer I was looking for. Haha. Thank you. I can see that Lua is going to incorporate much more than what I thought. This is gonna be a tough journey. Haha.

Thanks.
Topic archived. No new replies allowed.