如何使用 Luabind 和 C++创建一个资产管理类别?

发布于 2024-08-23 14:46:21 字数 489 浏览 3 评论 0原文

我已经做了无数次尝试来让它工作,但我所做的一切都会给我带来运行时错误。我一直在尝试让资产管理器来管理我的游戏引擎的内容,并且我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尐偏执 2024-08-30 14:46:21

您可能需要使用一些相关方法绑定向量类型本身,或者尝试 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文