如何使用 Luabind 和 C++创建一个资产管理类别?
我已经做了无数次尝试来让它工作,但我所做的一切都会给我带来运行时错误。我一直在尝试让资产管理器来管理我的游戏引擎的内容,并且我正在使用 lua 和 luabind 来编写脚本。到目前为止,编译所有内容、绑定类和变量以及从 lua 获取基本变量都没有问题。
我的问题是我使用 std::vector 来存储我的资产类的实例,而向量似乎与 luabind 不兼容。我知道我需要这个向量,因为我的 C++ 程序将使用它进行渲染和其他操作。
当我绑定管理器类和变量(包括包含我的资产类的向量)时,一切都会编译并运行良好。在我的 lua 脚本中,我可以成功创建新对象,但是当我尝试访问它们时,出现运行时错误。
总而言之:
我有一个类,它保存游戏对象的信息或有关其他数据的信息。
我有另一个包含资产类别向量的类。
当我尝试像访问常规 lua 表一样访问该向量时,出现运行时错误。
那么我应该在 C++ 和 luabind 中做什么来允许我修改资产管理器类中的类呢?
I've made countless attempts to get this working, but everything I do gives me run-time errors. I've been trying to make asset managers to manage content for my game engine, and I'm using lua and luabind for my scripting. Getting everything to compile, binding classes and variables, and getting basic variables back from lua have been no problem so far.
My problem is I'm using an std::vector to store instances of my asset classes, and vectors don't seem to get along with luabind. I know I will need this vector because my C++ program will use it for rendering and other things
When I bind my manager class and the variables, (including the vector containing my asset classes) everything compiles and runs fine. In my lua script I can create new objects successfully, but when I try to access them, I get a run-time error.
To sum everything up:
I have a class that holds information for a game object or information about some other data.
I have another class that contains a vector of asset classes.
When I try to access this vector like I would a regular lua table, I get a run-time error.
So what should I do in C++ and luabind that will allow me to modify the classes in my asset manager class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要使用一些相关方法绑定向量类型本身,或者尝试 Luabind 的 < code>return_stl_iterator,它提供对 STL 兼容容器的迭代(但不索引)。
如果您需要更多帮助,绑定的代码及其类型将会很有用。
You may need to bind the vector type itself with some relevant methods, or try Luabind's
return_stl_iterator
, which provides for iteration (but not indexing) over STL-compatible containers.If you need more help, the code for your bindings and their types would be useful.