luabind和静态字段

我正在尝试从类中导出静态字段:

class Foo
{
   const static int Var;
};

// luabind模块:
.def_readonly("Var", &Foo::Var);
// 我也尝试过
.def_readonly("Var", Foo::Var);
 错误:没有匹配的函数来调用‘luabind :: class_ <Foo> :: def_readonly(const char [6],const Foo&)’
 注意:模板<class Cclass D> luabind :: class_&luabind :: class_ :: def_readwrite(const char *,D C :: *)

我错过了什么吗?

原文链接 https://stackoverflow.com/questions/9451657

点赞
stackoverflow用户734069
stackoverflow用户734069

根据文档中清晰说明的内容,静态函数不能像其他成员函数一样添加。它们必须在 .scope 结构中进行作用域限定。

class_<foo>("foo")
    .def(constructor<>())
    .scope
    [
        class_<inner>("nested"),
        def("f", &f)
    ];

我不知道 def 的非成员函数版本是否有变量的 readonly 版本,如果有的话那就好了。如果没有,那么你必须将其公开为返回该值的函数。

2012-02-26 08:43:08