Jason Cheng
Jason Cheng

Reputation: 345

luabind 0.9.1 iterator always only pop the last object

all. I got a stranger problem by using luabind to read a array from lua script.

The lua script looks like this:

root = 
{
        id = 1,
        id = 2,
        id = 3
};

and the c++ code is looks like this: luabind::object data_root = luabind::globals(L)["root"];

for (luabind::iterator i(data_root), end; i != end; ++i)
{
    luabind::object data = *i;
    unsigned int id = luabind::object_cast<unsigned int>(data);
    std::cout << "id:" << id << std::endl;
}

the output is only:

id:3

I want to output all the elements of the [root], but it only output the last one and over.

Thank You, Jason :)

Upvotes: 1

Views: 311

Answers (1)

Puppy
Puppy

Reputation: 146910

There aren't multiple elements of root, it only has one. You assigned the key id to three different values, but the key only exists once and only has one value associated with it, so you basically only ever said root = { id = 3 }.

Upvotes: 2

Related Questions