sol icon indicating copy to clipboard operation
sol copied to clipboard

C++ iterators for Lua tables

Open thinlizzy opened this issue 9 years ago • 5 comments

Any plans on adding iteration capabilities in sol::table ?

thinlizzy avatar Feb 15 '16 00:02 thinlizzy

Try using

sol::table t = ...;
t.for_each( /* function that takes key, value */ ) ;

Note that this is only present in the develop branch of sol.

ThePhD avatar Feb 15 '16 00:02 ThePhD

error: 'class sol::table' has no member named 'for_each'

On Sun, Feb 14, 2016 at 7:57 PM, The Phantom Derpstorm < [email protected]> wrote:

Try using

sol::table t = ...; t.for_each( /* function that takes key, value */ ) ;

— Reply to this email directly or view it on GitHub https://github.com/Rapptz/sol/issues/72#issuecomment-184015985.

https://github.com/thinlizzy/ http://die-xml.googlecode.com/ - C++11 and C++14 open source wrappers and libraries for various purposes (XML, image, webserver... and even a MTG implementation) http://baudejogos.net - o único site brasileiro decente de jogos

thinlizzy avatar Feb 15 '16 06:02 thinlizzy

Please pull from the develop branch of Rapptz/sol (you're currently using the master branch) to get more updated features, or use the experimental version 2 of the library here.

ThePhD avatar Feb 15 '16 07:02 ThePhD

Hi! Does the develop branch also support checking if a table key exists?

I've seen sol2 has sol::optional, which also works for me. Perhaps I should early migrate to sol2, instead of trying the develop branch?

thinlizzy avatar Mar 27 '16 15:03 thinlizzy

Yes. sol2 is no longer experimental and has support for the features you're looking for.

ThePhD avatar Mar 27 '16 18:03 ThePhD