lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


const int table = // a positive lua index
for (lua_pushnil(L); lua_next(L, table) != 0; lua_pop(L, 1)) {
 if (lua_isstring(L, -2)) { // key
   if (lua_isstring(L, -1)) { // value
     myMap[lua_tostring(L, -2)] = lua_tostring(L, -1);
   }
 }
}

Ken Smith wrote:
I have a function in C++ that is exposed to Lua which takes a table
argument whose keys and values are all strings.  I'd like to convert
this into a std::map<std::string, std::string> but am having a hard
time coming up with a way to iterate over all the key-value pairs
using the C interface.  Any ideas?

  Ken Smith