是否有用于C++;? 我想调用一些来自Lua代码的C++函数,并在参数中传递Lua表,类似于: call_cpp_function_from_lua({ x = 10, y = 20 }) std::map<boost::varia

是否有用于C++;? 我想调用一些来自Lua代码的C++函数,并在参数中传递Lua表,类似于: call_cpp_function_from_lua({ x = 10, y = 20 }) std::map<boost::varia,c++,lua,iterator,lua-table,C++,Lua,Iterator,Lua Table,是否有用于C++;? 我想调用一些来自Lua代码的C++函数,并在参数中传递Lua表,类似于: call_cpp_function_from_lua({ x = 10, y = 20 }) std::map<boost::variant<LuaTypesList>, boost::variant<LuaTypesList>>::iterator it = getLuaTableBegin(); > CopycppAftyFaseFuxL

是否有用于C++;?

我想调用一些来自Lua代码的C++函数,并在参数中传递Lua表,类似于:

call_cpp_function_from_lua({ x = 10, y = 20 })
std::map<boost::variant<LuaTypesList>, boost::variant<LuaTypesList>>::iterator it = getLuaTableBegin();
<> > <代码> CopycppAftyFaseFuxLua<代码>,我想获得并使用迭代器来表示Lua表的C++表示,类似于:

call_cpp_function_from_lua({ x = 10, y = 20 })
std::map<boost::variant<LuaTypesList>, boost::variant<LuaTypesList>>::iterator it = getLuaTableBegin();
std::map::iterator it=getluatablebegen();

我可以使用C API来完成它,但是它很繁琐,容易出错,参见.P/>

实现了Lua表的C++迭代器。它有

Value::iterator
Value::const_iterator
类,允许迭代Lua表。下面是一个关于如何使用它们的简短示例:

// code from examples/cpp/value/iterate.cc:32

    QtLua::State state;

    // New lua table value
    state.exec_statements("table = { a = 1, b = 2, c = 3 }");

    QtLua::Value table = state["table"];

    // Iterate over lua table from C++ code
    for (QtLua::Value::const_iterator i = table.begin(); i != table.end(); i++)
      qDebug() << i.key().to_string_p()
               << i.value().to_string_p();
//示例代码/cpp/value/iterate.cc:32
QtLua::状态;
//新lua表值
state.exec_语句(“table={a=1,b=2,c=3}”);
QtLua::值表=状态[“表”];
//从C++代码中迭代LUA表
for(QtLua::Value::const_迭代器i=table.begin();i!=table.end();i++)

你可以看到在@ USER 1929 959中使用迭代器的不同例子:他是C++的迭代器,而不是Lua迭代器。但是它很容易出错。“你必须以这种方式编写代码。”除非你要图书馆。C++迭代器唯一的事情就是把它包在一个特定的接口中;该接口的实现是最困难的部分,Luabind可以做到这一点。不过,我不确定这是否是一个真正的答案,最初的维护人员已经决定在一段时间内不再继续该项目,因此,例如,您可能需要在某些配置中对其进行修补(GCC+Boost IIRC的最新版本)。它提供的不仅仅是向Lua和来自Lua的数据整理。@尼科尔-博拉:是的,我用C++迭代器接口询问库,它可以隐藏在LUA.C API中迭代的细节。