Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua, C++, any good introductions that go deeper than lua_open()?

Tags:

c++

lua

I googled a lot now, but all I find are "Hello World" examples for Lua with C++.

Situation: Game, big game. Has an in-game console, currently hard-coded in C++ (object-oriented and all), has a lot of if-else-if-else... blocks to check for the commands that the user entered in the console. Each command can change members of other classes of the game (like the command "speed 5" changes the variable double speed in class Car by calling Car::setSpeed(5)) and also gives an output back to the console about the result. There are also commands that do more "behind the scenes" than only changing a variable, this should also be done by Lua and only the final result passed back to the C++ code (console output + changed variables in the correct class).

Where/how/with what should I start to convert the code behind this console command functions to Lua? Like this: User enters "speed 5" in the console, then Lua calls Car::setSpeed(5) and then Lua reports back to the C++ console. Instead of hard-coding the code behind the commands they should be written in Lua, but the whole rest of the game should stay in C++ (like my classes and there members and the console framework).

Any good tutorials? Any hints where to start? Some experiences to share?

Thanks in advance

like image 473
blubberbernd Avatar asked Jul 08 '11 16:07

blubberbernd


1 Answers

Get a copy of Programming in Lua if you haven't already. The section describing interop with C (and hence C++) is almost 100 pages, and much more than a 'hello world'.

There's no specific C++ binding information in the book, but if your C++ compiler has any RTTI capabilities,that can be helpful. That's how we integrate lua with C++Builder

like image 129
Roddy Avatar answered Sep 18 '22 05:09

Roddy