【问题标题】:luabind and static fieldsluabind 和静态字段
【发布时间】:2012-03-16 03:17:39
【问题描述】:

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

class Foo
{
   const static int Var;
};

// luabind module:
.def_readonly("Var", &Foo::Var);
// I've also tried
.def_readonly("Var", Foo::Var);
 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::*)

我错过了什么?

【问题讨论】:

    标签: c++ static lua luabind


    【解决方案1】:

    As clearly stated in the documentation,静态函数(除其他外)不能添加为成员。它们必须在一个特殊的 .scope 构造中限定范围。

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

    我不知道def 的非成员函数版本是否有变量的readonly 版本,但它可能。如果没有,那么您必须将其公开为返回值的函数。

    【讨论】:

    • 好的,谢谢。我错过了这不仅适用于静态函数。
    猜你喜欢
    • 2017-12-26
    • 1970-01-01
    • 1970-01-01
    • 2012-06-14
    • 2016-08-31
    • 2015-06-28
    • 2021-03-03
    • 1970-01-01
    • 2012-06-21
    相关资源
    最近更新 更多