在返回时出现了“尝试使用未注册的类”的 luabind 错误。

我目前正在使用luabind绑定一个类(确切地说是来自SFML 2.0的sf::Time),但是我一直从luabind中得到一个异常。这是我的绑定代码:

            using namespace luabind;

            module(L, "system")
            [
                class_<sf::Time>("Time")
                    .def(constructor<>())
                    .def("toSeconds", &sf::Time::asSeconds)
                    .def("toMilliseconds", &sf::Time::asMilliseconds)
                    .def("toMicroseconds", &sf::Time::asMicroseconds)
                    .def(self == other<sf::Time>())
                    .def(self < other<sf::Time>())
                    .def(self <= other<sf::Time>())
                    .def(self - other<sf::Time>())
                    .def(self + other<sf::Time>())
                    .def(self * float())
                    .def(self / float())
                    .scope
                    [
                        def("seconds", &sf::seconds),
                        def("milliseconds", &sf::milliseconds),
                        def("microseconds", &sf::microseconds)
                    ],
...

我的lua代码是:

local t = system.Time.seconds(10)

sf::seconds的签名是:

sf::Time sf::seconds(float)

我尝试过包装对sf::seconds的调用,并返回sf::Time,我也尝试过使用sf::Time*作为返回值。无论如何,我都一直收到错误。

有什么想法吗?

编辑:

我已经测试了这个类本身,我可以在Lua中使用system.Time()创建它,没有问题。所有的方法都正常工作,但system.Time.seconds和其他静态方法不起作用。

点赞