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);
42 ns_test(const char*) {}
45 void operator=(const T
&) {}
50 using namespace luabind
;
52 lua_State
* L
= lua_open();
58 class_
<test_class
>("test")
60 .def("f", &test_class::f
, yield
)
64 dostring(L
, "function g() a = test() for i = 1, 10 do print(a:f()) end end");
66 lua_pushstring(L
, "j");
67 lua_pushcclosure(L
, j
, 0);
68 lua_settable(L
, LUA_GLOBALSINDEX
);
70 lua_State
* thread
= lua_newthread(L
);
71 lua_pushstring(thread
, "g");
72 lua_gettable(thread
, LUA_GLOBALSINDEX
);
74 if (lua_resume(thread
, 0))
76 std::cout
<< "error: " << lua_tostring(thread
, -1) << '\n';
79 for (int i
= 0; i
< 10; ++i
)
81 std::cout
<< "iteration: " << i
<< ", top: " << lua_gettop(thread
) << '\n';
83 lua_resume(thread
, lua_gettop(thread
));