lua-users home
lua-l archive

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


Can I add new rows to the table while I iterate over
all the key-value pairs?

Thanks A Lot!!,
Vertexar

--- Ken Smith <kgsmith@gmail.com> wrote:

> It's funny how I never saw lua_next in all my
> readings of the
> reference manual :)  Thank you very much for this
> concise solution.
> 
>    Ken
> 
> On 4/30/07, trepan <trepan@rogers.com> wrote:
> > 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
> > >
> >
> >
> 
> 
> -- 
> If you're any good at what you do, it'll make you
> miserable.
> 


------------------------------------
Dark Designs
www.darkdesigns.com.ar
Sign our Guestbook!

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com