C++11乱绑定集成,函数失败
C++11 luabind integration, function failing
我正在尝试用luabind
将LUA集成到我的程序中,但我遇到了一个很大的障碍。
我对LUA的调用约定非常陌生,我觉得我错过了一些简单的东西。
这是我的C++代码:
struct app_t
{
//...
void exit();
void reset();
resource_mgr_t resources;
//...
};
struct resource_mgr_t
{
//...
void prune();
void purge();
//...
};
extern app_t app;
我的luabind
模块:
luabind::module(state)
[
luabind::class_<resource_mgr_t>("resource_mgr")
.def("prune", &resource_mgr_t::prune)
.def("purge", &resource_mgr_t::purge)
];
luabind::module(state)
[
luabind::class_<app_t>("app")
.def("exit", &app_t::exit)
.def("reset", &app_t::reset)
.def_readonly("resources", &app_t::resources)
];
luabind::globals(state)["app"] = &app;
我可以很好地执行以下lua命令:
app:exit()
app:reset()
但是,以下调用失败:
app.resources:purge()
出现以下错误:
[string "app.resources:purge()"]:1: attempt to index field 'resources' (a function value)
非常感谢您的帮助!
当绑定非基元类型的成员时,自动生成的getter函数将返回对它的引用。
而且,就像在app:reset()
中一样,resources是一个实例成员字段。
所以,像这样使用它:
app:resources():purge()
相关文章:
- 函数返回时,带指针的复制构造函数失败
- 为什么 std::get<T> 其中 T 是调用 constexpr 函数失败的结果?
- 在 if 语句中调用重载构造函数失败
- 使用特征函数失败
- 为什么通过通用引用运算符 (&&) 将变量的引用传递给 Varadic 模板函数失败?
- 为什么我的代码在没有 chroot 函数的情况下工作,但使用 chroot 函数失败?
- 非常量调用 const 成员函数失败,只读位置C++
- 对于实际指针类型,用于检测类似指针(可取消引用)类型的模板函数失败
- C++模板化类默认构造函数失败
- STD :: MAP EMPLECE通过显式构造函数失败
- 为什么 std::apply 使用泛型函数失败
- 从返回绑定中获取函数失败
- 运算符 == 重载函数失败
- 打开不存在的文件时如何使流构造函数失败?
- 为线程构造函数传递引用以将其绑定到函数失败
- 显式DLL 1函数失败
- 模板参数扣除/替换使用Lambda表达式使用高阶函数失败
- 来自(QT)插件的调用函数失败
- 什么错误的逻辑导致我的链表的这个 push_back(..) 函数失败?
- 复制构造函数失败..重载,动态分配