Luabind: "找不到匹配的重载,候选项:"

我有一个简单的类通过luabind在LUA中使用

这是绑定代码:

void LogManager::luaBindImpl() const
{
    using namespace luabind;
    lua_State* state(Supervisor::getSingleton().getManager<LuaManager>()->state());

    // LogManager
    module(state)
    [
        class_<LogManager>("LogManager")
        .enum_("LogType")
        [
             value("Info", 1)
            ,value("Warning", 2)
            ,value("Critical", 3)
            ,value("Debug", 4)
        ]
        .def("log", &LogManager::log)
        .def("registerSource", &LogManager::registerSource)
    ];

    // Add to globals
    globals(state)["LogManager"] = this;
};  // eo luaBindImpl

这是我的LUA:

LogManager.registerSource("lol");

但是我得到了标题中提到的错误(这直接来自我的日志文件):

00:00:00:0520- lua:Exception - No matching overload found, candidates:
void registerSource(LogManager&,std::string const&)

我一直为此苦苦思索,却看不出我的错误在哪里。有人能解释一下吗? :)

原文链接 https://stackoverflow.com/questions/6152175

点赞
stackoverflow用户169828
stackoverflow用户169828

在 Lua 部分,你需要使用冒号(:)代替点(.):

LogManager:registerSource("lol");

并且你意识到全局变量 LogManager 与类 LogManager 同名;这样你将无法使用枚举常量,例如 LogManager.Info 将返回 nil。

2011-05-27 13:37:46