diff options
author | Boris Nagaev <bnagaev@gmail.com> | 2014-12-06 18:59:05 (GMT) |
---|---|---|
committer | Boris Nagaev <bnagaev@gmail.com> | 2014-12-06 19:11:16 (GMT) |
commit | 600fc832c0d0dbd950442b4e36ef1ecfe23d8346 (patch) | |
tree | 888400cc060958130de01711137a6b36e55c2f7d /src | |
parent | bba46dda8b3ca1491775cd6abd06b7c622fbd20a (diff) | |
download | mxe-600fc832c0d0dbd950442b4e36ef1ecfe23d8346.zip mxe-600fc832c0d0dbd950442b4e36ef1ecfe23d8346.tar.gz mxe-600fc832c0d0dbd950442b4e36ef1ecfe23d8346.tar.bz2 |
luabind: test iterating list of numbers
Diffstat (limited to 'src')
-rw-r--r-- | src/luabind-test.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/luabind-test.cpp b/src/luabind-test.cpp index 0df7f19..bbb4f2a 100644 --- a/src/luabind-test.cpp +++ b/src/luabind-test.cpp @@ -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); } |