2

LuaコードからC++関数を呼び出し、Luaテーブルをパラメーターに渡します。次のようになります。

call_cpp_function_from_lua({ x = 10, y = 20 })

call_cpp_function_from_luaLuaテーブルのC++表現用のイテレータを取得して使用したいのですが、次のようになります。

std::map<boost::variant<LuaTypesList>, boost::variant<LuaTypesList>>::iterator it = getLuaTableBegin();

C APIを使用してそれを行うことはできますが、エラーが発生しやすい面倒です。C++からLuaテーブルを反復処理するを参照してください。

4

1 に答える 1

1

QtLua ライブラリは、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();
于 2013-03-10T10:57:33.200 に答える