2 #include <luabind/yield_policy.hpp>
7 LUABIND_ANONYMOUS_FIX
int feedback
= 0;
15 return const_cast<int&>(n
)++;
29 return lua_yield(L
, 1);
39 using namespace luabind
;
41 lua_State
* L
= lua_open();
49 class_
<test_class
>("test")
51 .def("f", &test_class::f
, yield
)
54 dostring(L
, "function g() a = test() for i = 1, 10 do print(a:f()) end end");
56 lua_pushstring(L
, "j");
57 lua_pushcclosure(L
, j
, 0);
58 lua_settable(L
, LUA_GLOBALSINDEX
);
60 lua_State
* thread
= lua_newthread(L
);
61 lua_pushstring(thread
, "g");
62 lua_gettable(thread
, LUA_GLOBALSINDEX
);
64 if (lua_resume(thread
, 0))
66 std::cout
<< "error: " << lua_tostring(thread
, -1) << '\n';
69 for (int i
= 0; i
< 10; ++i
)
71 std::cout
<< "iteration: " << i
<< ", top: " << lua_gettop(thread
) << '\n';
73 lua_resume(thread
, lua_gettop(thread
));