Max*_*rai 5 c++ lua static luabind
我正在尝试从类中导出静态字段:
class Foo
{
const static int Var;
};
// luabind module:
.def_readonly("Var", &Foo::Var);
// I've also tried
.def_readonly("Var", Foo::Var);
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)error: no matching function for call to ‘luabind::class_<Foo>::def_readonly(const char [6], const Foo&)’ note: template<class C, class D> luabind::class_& luabind::class_::def_readwrite(const char*, D C::*)
我错过了什么?
正如文档中明确指出的,静态函数(除其他外)不能添加为成员。它们必须处于特殊.scope
构造的范围内。
class_<foo>("foo")
.def(constructor<>())
.scope
[
class_<inner>("nested"),
def("f", &f)
];
Run Code Online (Sandbox Code Playgroud)
我不知道 的非成员函数版本是否def
有readonly
变量版本,但可能有。如果没有,那么您必须将其公开为返回该值的函数。