The luabind documentation says to call a Lua-derived virtual member from C++, you create a wrapper class derived from luabind::wrap_base and call the function like so:
class BaseWrapper : public Base, public luabind::wrap_base
{
public:
virtual void foo()
{
call<void>("foo");
}
};
So far so good – I have this much working.
But how do I implement BaseWrapper::foo() to call the overridden foo (on the Lua side) as a coroutine (using resume_function) instead of calling it directly with call?
This is how it’s done with non-member functions:
luabind::object func = luabind::globals(L)["bar"];
luabind::resume_function<void>(func);
I think what I need to know is how to get func for foo (as implemented by the Lua-derived class), and then my existing resume_function logic should work as-is.
So I’ve figured out the answer to this problem. It seems that the simplest solution is to pass
selffrom Lua when you construct the object and then look up the function from its table:On the C++ side:
And in Lua: