0

I'm attempting to replace an existing implementation of a queue class written in Lua with the STL Queue class. I'm not sure why this is failing, or how to approach fixing it. Below is some sample code that exhibits the same behavior, along with the error output. Thanks in advance!

#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)
    ];
}


And the gcc output:

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
Joe
  • 4,585
  • 3
  • 37
  • 51

3 Answers3

4

Most likely, you have an overloaded function in your queue implementation. Thus, when you take the address, the compiler doesn't know what to do because you could mean any overloaded function.

Puppy
  • 144,682
  • 38
  • 256
  • 465
2

As DeadMG points out, in the case of overloaded functions you have to tell the compiler which version to pick, e.g. for the const versions:

typedef const XYZ_QUEUE_T::value_type& (XYZ_QUEUE_T::*ConstRefConstType)() const;

class_<XYZ_QUEUE_T>("XYZ_QUEUE_T")
    // ...
    .def("front", (ConstRefConstType)&XYZ_QUEUE_T::front)
    .def("back" , (ConstRefConstType)&XYZ_QUEUE_T::back)
    // ...

The luabind documentation includes an example of this.

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
0

This:

class_("XYZ_QUEUE_T")

Should be:

class_<XYZ_QUEUE_T>("XYZ_QUEUE_T")

The string is the typename that Lua sees, while the template parameter is the C++ type you're using.

Oh, and it does little good to expose the queue to Lua if you don't expose the objects that the queue stores.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • Gah, I had that in there, but I forgot to HTML code the < symbol. Also, defining XYZ_T didn't seem to affect the issue. Long story short, same issue :-( – Joe Jul 06 '11 at 23:05