luabind::iterator for arrays
Ken Smith <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
I have a Lua table that contains array elements and I want to use
luabind::iterator to visit them in order. Is this possible?
The input array looks like this.
document =
{
name = 'simple',
insert = table.insert,
}
for i = 0,9 do
document:insert
{
name = 'row ' .. tostring(i)
}
end
I read it with luabind::iterator like this.
for (luabind::iterator i(table), end; i != end; ++i)
{
// basically just pushing back into an std::list
}
A serialization method renders this to an ostream and the result is this.
document =
{
name = "simple",
{
name = "row 6",
},
{
name = "row 0",
},
{
name = "row 1",
},
{
name = "row 3",
},
{
name = "row 7",
},
{
name = "row 8",
},
{
name = "row 4",
},
{
name = "row 9",
},
{
name = "row 2",
},
{
name = "row 5",
},
}
luabind::raw_iterator behaves the same. Is traversing the list in
array order possible with luabind::iterator or should I just use
lua_rawgeti?
Regards,
Ken
------------------------------------------------------------------------------
This SF.net email is sponsored by
Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev