【发布时间】:2009-09-11 23:38:19
【问题描述】:
我有这个必须匹配的函数签名
typedef int (*lua_CFunction) (lua_State *L);//target sig
这是我目前所拥有的:
//somewhere else...
...
registerFunction<LuaEngine>("testFunc", &LuaEngine::testFunc, this);
...
//0 arg callback
void funcCallback0(boost::function<void ()> func, lua_State *state)
{
func();
}
template<typename SelfType>
void registerFunction(const std::string &funcName, boost::function<void (SelfType*)> func, SelfType *self)
{
//funcToCall has to match lua_CFunction
boost::function<void (lua_State *)> funcToCall = boost::bind(&LuaEngine::funcCallback0, this,
boost::bind(func, self), _1);
lua_register(_luaState, funcName.c_str(), funcToCall);
}
然而,lua_register(_luaState...,它仍在抱怨转换问题
错误 1 错误 C2664: 'lua_pushcclosure' : 无法转换 参数 2 来自 '升压::功能'到 'lua_CFunction'
有人知道怎么解决吗?
【问题讨论】:
-
一个更广泛的问题,涉及将
boost::function转换为纯 C 指针的相同一般问题:stackoverflow.com/questions/282372/…
标签: c++ lua function-pointers boost-bind boost-function