lua-users home
lua-l archive

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


Am 03.12.2012 um 22:44 schrieb Coda Highland:

> On Mon, Dec 3, 2012 at 1:47 PM, Philipp Kraus
> <philipp.kraus@flashpixx.de> wrote:
>> Hello,
>> 
>> I use lua_createtable for push std::vectors to my Lua function, it works
>> well.
>> I would like to push also the std::map as key-value structure to Lua,
>> so I have got
>> 
>> lua_createtable(m_lua, p_map.size(), 0);
>> 
>> for( typename std::map<std::string, int>::const_iterator it = p_map.begin();
>> it != p_map.end(); ++it )
>> 
>> {
>>  lua_pushstring(m_lua, it->first.c_str());
>>  lua_pushnumber(m_lua, it->second);
>>  // should here a pop call on the stack?
>> }
>> // should here also a pop call on the stack?
>> 
>> Which calls must be added, so I can use a table in the script, that has a
>> structure
>> table["key"] = value ?
>> 
>> 
>> In this case another question is occured: Can I used also a std::multimap?
>> So can Lua handle tables with
>> duplicated keys or must be the keys unique?
>> 
>> Thanks
>> 
>> Phil
>> 
> 
> You'd use lua_setfield() after those two pushes, and that'll pop them
> for you, and Lua keys have to be unique. Check the docs for more
> details.

Thanks, but how can I use the setfield with a map like std::map<int, std::String>.
setfield need a char value.

Thanks

Phil