Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I put a lua_table in another table to build a multi-dimensional array via C++?
    primarykey
    data
    text
    <p>for my game im trying to accomplish the following array structure by C++ because the data come from an external source and should be available in a lua_script.</p> <p>The array structure should look like this: (The data are in a map, the map contains the name of the variable and a list of Pairs (Each pair is a key value pair considered to be one element in one subarray)...</p> <p>The data prepared in the map are complete and the structure is definetly okay. So basically I have</p> <pre><code>typedef std::map&lt;std::string, std::list&lt;std::pair&gt; &gt;; /\index(e.g: sword) /\ /\ || || || Pair: Contains two strings (key/value pair) || List of Pairs for each array </code></pre> <hr> <pre><code>items = { ["sword"] = {item_id = 1294, price = 500}, ["axe"] = {item_id = 1678, price = 200}, ["red gem"] = {item_id = 1679, price = 2000}, } </code></pre> <p>What I got so far now is:</p> <pre><code>for(ArrayMap::iterator it = this-&gt;npc-&gt;arrayMap.begin(); it != this-&gt;npc-&gt;arrayMap.end(); it++) { std::string arrayName = (*it).first; if((*it).second.size() &gt; 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()); } } </code></pre> <p>But this will only generate the following structure:</p> <pre><code>(table) [item_id] = (string) 2000 [name] = (string) sword [price] = (string) 500 </code></pre> <p>The problem is that the table can ofcourse only contain each index once. Thatswhy I need something like "a table in a table", is that possible?</p> <p>Is there a way to achieve this? Im glad for any hints.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload