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 🙂
There aren’t multiple elements of root, it only has one. You assigned the key
idto three different values, but the key only exists once and only has one value associated with it, so you basically only ever saidroot = { id = 3 }.