lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Side note. I tried to compile your example. It was not easy because I
had to install both luabind and the huge Boost++ library.
For the matter of comparison, I tried to port that code to my
LuaClassBasedCall binding (a single header file).
I realized that unlike luabind, my library has no special support for
coroutines, so it was easier to create / resume the coroutine in Lua
language.
Still the resulting code is shorter, and IMHO easier to understand...


#include <iostream>
#include <lgencall.hpp>

using namespace std;
using namespace lua;

int func(lua_State* L)
{
 cout << "c func" << endl;
 return lua_yield(L, 0);
}

int main()
{
 Lua<> L;

 const char* error = L.PCall(
  "local func = ...\n"
  "function funcWrap() func(); print('resumed') end\n"
  "coro = coroutine.create(funcWrap)\n"
  "coroutine.resume(coro)", Input(func));
 if(error)
  cout << error << endl;

 cin.get();
}