luabind: test iterating list of numbers

This commit is contained in:
Boris Nagaev 2014-12-06 21:59:05 +03:00
parent bba46dda8b
commit 600fc832c0
1 changed files with 14 additions and 0 deletions

View File

@ -1,3 +1,4 @@
#include <cassert>
#include <iostream>
#include <string>
@ -44,6 +45,19 @@ int main()
{
lua_State* L = luaL_newstate();
init(L);
// hello world
luaL_dostring(L, "greet()");
// class
luaL_dostring(L, "t = Test('123'); assert(t:name() == '123'");
// iterate Lua table in C++
luaL_dostring(L, "list123 = {1, 2, 3}");
int sum = 0;
lua_getglobal(L, "list123");
luabind::object list123(luabind::from_stack(L, -1));
lua_pop(L, 1);
for (luabind::iterator it(list123), end; it != end; ++it) {
luabind::object item = *it;
sum += luabind::object_cast<int>(item);
}
assert(sum == 6);
}