我想使用 luabridge 将一个函数从一个 Lua_State 复制到另一个。
luabridge 提供了一个被调用的函数addFunction(const char * name,FP fp)
和一个被调用的函数getGlobal(lua_State* L,const char*)
,它返回一个LuaRef
具有重载运算符的类型的对象。我正在使用 multimap 来存储要复制的函数的名称。
该函数addFunction()
不支持使用指向类的指针,因此我不能getGlobal().operator()
直接传递
//get all functions that match the Criteria
std::pair<acc_map_iter, acc_map_iter> range = sec_map->equal_range(acl);
//Add them to the first State
std::for_each(range.first, range.second, [&](acc_map_iter iter){
script->compilerContext->addFunction(iter->second.c_str(), [&](/*args...?*/)
{
return luabridge::getGlobal(sec_state, iter->second.c_str()).operator(/*args...?*/);
});
});
我可以以某种方式使 lambda 接受来自addFunction()
. 有什么诀窍还是根本不可能?