0

私のゲームでは、データが外部ソースから取得され、lua_script で使用できる必要があるため、C++ で次の配列構造を達成しようとしています。

配列構造は次のようになります: (データはマップ内にあり、マップには変数の名前とペアのリストが含まれます (各ペアは、1 つのサブ配列の 1 つの要素と見なされるキーと値のペアです)...

マップに用意されたデータは完成しており、構造は間違いなく大丈夫です。だから基本的に私は持っています

typedef std::map<std::string, std::list<std::pair> >;
                  /\index(e.g: sword) /\       /\
                                      ||       ||
                                      ||    Pair: Contains two strings (key/value pair)
                                      ||
                                      List of Pairs for each array

items = {
    ["sword"] = {item_id = 1294, price = 500},
    ["axe"] = {item_id = 1678, price = 200},
    ["red gem"] = {item_id = 1679, price = 2000},
}

これまでに得たものは次のとおりです。

for(ArrayMap::iterator it = this->npc->arrayMap.begin(); it != this->npc->arrayMap.end(); it++) {
    std::string arrayName = (*it).first;
    if((*it).second.size() > 0) {
        lua_newtable(luaState);
        for(ArrayEntryList::iterator itt = (*it).second.begin(); itt != (*it).second.end(); itt++) {
            LuaScript::setField(luaState, (*itt).first.c_str(), (*itt).second.c_str());
        }
        lua_setglobal(luaState, arrayName.c_str());
    }
}

ただし、これは次の構造のみを生成します。

(table)
[item_id] = (string) 2000
[name] = (string) sword
[price] = (string) 500

問題は、テーブルに各インデックスを一度しか含めることができないことです。そのため、「テーブルの中のテーブル」のようなものが必要なのですが、それは可能ですか?

これを達成する方法はありますか?ヒントがあればうれしいです。

4

1 に答える 1