需要帮助开始将 lua 集成到 c++游戏
我需要帮助将 lua 集成到我的游戏中。我对 lua 只了解一点点,因为我刚刚开始学习脚本(一般来说)。我读过有关 lua 的教程,但大多数只是告诉我如何在 c++ 代码中绑定 lua(我已经用 LuaBind 成功做到了),或者解释了 lua 中的功能。
假设我有一个“玩家”类和“障碍”类。 Obstacle 类具有以下功能:
class Obstacle {
// ... member vars
// functions that will behave differently based on script :
void onTouchPlayer(Player* player);
void onUpdate(float deltaTime);
}
onTouchPlayer 和 onUpdate 旨在根据脚本表现不同。
让我困惑的是脚本中要写什么,以及如何在c++中调用它?如果我已经使用 LuaBind 将 Player 类导出到 Lua,那么我如何在 onTouchPlayer() 处杀死玩家并使用 lua 在 onUpdate 函数处随机移动障碍物?
I need help integrating lua in my game. I know only a little about lua, since I just started learning scripting (in general). I've read tutorials about lua, but most of them are only tell me how to bind lua in c++ code (which I've managed to do that with LuaBind), or explaining features in lua.
Let's say I have a "Player" class and "Obstacle" class.
Obstacle class have these functions :
class Obstacle {
// ... member vars
// functions that will behave differently based on script :
void onTouchPlayer(Player* player);
void onUpdate(float deltaTime);
}
onTouchPlayer and onUpdate is meant to behave differently based on script.
What confuses me is what to write in the script, and how to call it in c++? If I already have Player class exported to Lua with LuaBind, how can I, for example, kill player at onTouchPlayer() and move the obstacle randomly at onUpdate function with lua?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有很多教程与此相关。 google 搜索会给你一些。
我个人喜欢这个:
http://csl.sublevel3.org/lua/
There are lots of tutorials out there dealing with that. A google search will give you some.
I personally liked this one:
http://csl.sublevel3.org/lua/
Lua开发指南(5.0)的下一页告诉你如何从C环境调用lua函数。
http://www.lua.org/pil/25.2.html
The following page of the Lua Development Guide (5.0) tells you how to call lua functions from the C environment.
http://www.lua.org/pil/25.2.html