开发者

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

I googled a lot now, but a开发者_StackOverflow社区ll 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


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


I cannot give you a lot of hints as I only used lua to play around with scripting.
But I found luabind to be much more useful in c++ as plain lua. Maybe the tutorials in there can help you too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜