Original Post
// lua content
table1 = {}
table1 ["arth"] = "meshName"
table1 ["minotaur"] = "meshName"
table1 ["villager"] = "meshName"
table1 ["footman"] = "meshName"
table1 ["skin_tiny"] = "meshName"
table2 = {}
table2 ["arth"] = "root"
table2 ["minotaur"] = "root"
table2 ["villager"] = "root"
table2 ["footman"] = "root"
table2 ["ogre"] = "root"
table2 = {}
table2["0"] = "wall00"
table2["111"] = "wall01"
table2["88"] = "wall02"
table2["33"] = "wall03"
table2["111"] = "wall04"
table2["0"] = "wall05"
table2["33"] = "wall06"
table2["0"] = "wall07"
table2["0"] = "wall08"
table2["0"] = "wall09"
table2["0"] = "wall10"
table2["88"] = "wall11"
table1 ["0.6"] = "key"
table1 ["2.2"] = "mouse"
// c++
lua_getglobal(L, tableName.c_str() );
tableInStack(L);
void Lua::tableInStack(lua_State * L , int tableIndex)
{
lua_pushnil(L);
// pop nil and put first key/value at step 1
while(lua_next(L, tableIndex) != 0)
{
// value at top and 处理他
if(lua_isstring(L, -1))
//printf("%s = %s\n", lua_tostring(L, -2), lua_tostring(L, -1));
//m_data[lua_tostring(L, -2)] = lua_tostring(L, -1);
m_data.insert( MapStr::value_type(lua_tostring(L, -1), lua_tostring(L, -2)) );
else if(lua_isnumber(L, -1))
//printf("%s = %d\n", lua_tostring(L, -2), lua_tonumber(L, -1));
m_numList.push_back(lua_tonumber(L, -1));
else if(lua_istable(L, -1))
tableInStack(L, tableIndex);
//pop value , keep key
lua_pop(L, 1);
}
}