Luabind 编译时错误 无法推导模板参数

我遇到了一些我不理解的编译时错误。我正在使用来自sourceforge的luabind库,版本为0.9.1,并且我正在尝试绑定来自MyGUI的函数。我正在使用Visual Studio 2012和Lua 5.1。尽管看起来源自其他文件,但错误会在下面的cpp代码编译期间出现。错误使我认为我在某个地方没有正确定义签名,但是我的IntelliSense没有指出任何这样的问题。

涉及到的代码:

LuaMachine.cpp(Stackoverflow投诉身体太长,所以我把它放在了pastebin上)

给出的错误:

Error   4   error C2780: 'void luabind::detail::value_wrapper_converter<U>::apply(lua_State *,const T &)' : expects 2 arguments - 3 provided    c:\users\jake kiesel\space-junk\c++ project\3rdpartycode\include\luabind\detail\call.hpp    293 1   Space Junk
Error   3   error C2784: 'int luabind::detail::value_wrapper_converter<U>::match(lua_State *,luabind::detail::by_const_reference<T>,int)' : could not deduce template argument for 'luabind::detail::by_const_reference<T>' from 'luabind::detail::by_reference<T>' c:\users\jake kiesel\space-junk\c++ project\3rdpartycode\include\boost\preprocessor\iteration\detail\local.hpp  34  1   Space Junk
Error   2   error C2784: 'int luabind::detail::value_wrapper_converter<U>::match(lua_State *,luabind::detail::by_value<T>,int)' : could not deduce template argument for 'luabind::detail::by_value<T>' from 'luabind::detail::by_reference<T>' c:\users\jake kiesel\space-junk\c++ project\3rdpartycode\include\boost\preprocessor\iteration\detail\local.hpp  34  1   Space Junk
Error   6   error C2784: 'T luabind::detail::value_wrapper_converter<U>::apply(lua_State *,luabind::detail::by_const_reference<T>,int)' : could not deduce template argument for 'luabind::detail::by_const_reference<T>' from 'luabind::detail::by_reference<T>'   c:\users\jake kiesel\space-junk\c++ project\3rdpartycode\include\luabind\detail\call.hpp    293 1   Space Junk
Error   5   error C2784: 'T luabind::detail::value_wrapper_converter<U>::apply(lua_State *,luabind::detail::by_value<T>,int)' : could not deduce template argument for 'luabind::detail::by_value<T>' from 'luabind::detail::by_reference<T>'   c:\users\jake kiesel\space-junk\c++ project\3rdpartycode\include\luabind\detail\call.hpp    293 1   Space Junk

编辑:

通过进一步研究,我发现以下是触发这些错误的问题行。这些行在wrapGuiManager函数中。

luabind::def(“destroyWidgets”,&MyGUIManager :: destroyWidgets)

luabind::def(“unloadLayout”,&MyGUIManager :: unloadLayout),

这些是这些函数的函数声明:

void unloadLayout(luabind :: object&table);

void destroyWidgets(luabind :: object&table);

这两个函数都是独特的,因为它们使用luabind :: object&参数。它们应该能够采取用作包含MyGUI小部件数组的表的Lua表。

点赞
用户2125788
用户2125788

我做到了!:D 问题的原因在于以下两行代码:

luabind::def("destroyWidgets", &MyGUIManager::destroyWidgets)

luabind::def("unloadLayout", &MyGUIManager::unloadLayout)

这两个函数都需要使用 luabind::object&,但是 luabind 并不支持这种方式,它需要函数接受 luabind::object 而不是带引用的 luabind::object&。因此,正确的函数声明应该是:

void unloadLayout(luabind::object table);
void destroyWidgets(luabind::object table);
2014-09-29 21:44:01