c++ - 通过 Luabind 将 STL 队列暴露给 Lua

标签 c++ stl lua queue luabind

我正在尝试用 STL 队列类替换用 Lua 编写的队列类的现有实现。我不确定为什么会失败,或者如何解决它。下面是一些表现出相同行为的示例代码,以及错误输出。提前致谢!

#include <luabind/luabind.hpp>
#include <queue>

struct XYZ_T
{
    short x, y, z;
};

typedef std::queue<XYZ_T> XYZ_QUEUE_T;

extern "C" int init(lua_State *L)
{
    using namespace luabind;

    open(L);

    module(L)
    [
        class_<XZY_T>("XYZ_T")
            .def(constructor<>())
            .def_readwrite("x", &XYZ_T::x)
            .def_readwrite("y", &XYZ_T::y)
            .def_readwrite("z", &XYZ_T::z),

        class_<XYZ_QUEUE_T>("XYZ_QUEUE_T")
            .def(constructor<>())
            .def("push",  &XYZ_QUEUE_T::push)
            .def("pop",   &XYZ_QUEUE_T::pop)
            .def("front", &XYZ_QUEUE_T::front)
            .def("back",  &XYZ_QUEUE_T::back)
            .def("empty", &XYZ_QUEUE_T::empty)
            .def("size",  &XYZ_QUEUE_T::size)
    ];
}


以及 gcc 输出:

g++ -o test_luabind.os -c -fPIC -Iinclude -I$VALID_INCLUDE_DIR /packages/build_env/include test_luabind.cpp
test_luabind.cpp: In function `int init(lua_State*)':
test_luabind.cpp:27: error: no matching function for call to `
   luabind::class_<XYZ_QUEUE_T, luabind::detail::unspecified, 
   luabind::detail::unspecified, luabind::detail::unspecified>::def(const 
   char[6], <unknown type>)'
test_luabind.cpp:32: error: parse error before `(' token

最佳答案

很可能,您的队列实现中有一个重载函数。因此,当您获取地址时,编译器不知道该怎么做,因为您可能指的是任何重载函数。

关于c++ - 通过 Luabind 将 STL 队列暴露给 Lua,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6604022/

相关文章:

c++ - 它返回新对象吗?

c++ - 尽管我已经初始化了这个链表,但链表指向 NULL

c++ - 在堆栈上为小字符串分配字符串类?

c++ - 关于c++中 vector 的地址

lua - #在Lua中是什么意思?

java - 在 LuaJ 中需要 Java 类

c++ - 具有部分固定类型的递归数据类型

c++ - 标准头文件 <new> 中 std::nothrow 和 std::new_handler 的用途是什么

c++ - 将 std::bind2nd 与引用一起使用

redis - 通过Lua在Redis中设置多个key