将 luabind 派生成员作为协程调用
luabind 文档说要从 C++ 调用 Lua 派生的虚拟成员,您需要创建一个派生自 luabind::wrap_base 的包装类,并像这样调用该函数:
class BaseWrapper : public Base, public luabind::wrap_base
{
public:
virtual void foo()
{
call<void>("foo");
}
};
到目前为止一切顺利 - 我有这么多工作。
但是我如何实现BaseWrapper::foo()
来调用重写的foo
(在Lua端)作为协程(使用resume_function
)而不是直接使用 call
调用它?
这就是非成员函数的实现方式:
luabind::object func = luabind::globals(L)["bar"];
luabind::resume_function<void>(func);
我想我需要知道的是如何获取 foo
的 func
(由 Lua 派生类实现),然后我现有的 resume_function
逻辑应该按原样工作。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以我已经找到了这个问题的答案。看起来最简单的解决方案是在构造对象时从 Lua 传递 self,然后从其表中查找函数:
在 C++ 方面:
在 Lua 中:
So I've figured out the answer to this problem. It seems that the simplest solution is to pass
self
from Lua when you construct the object and then look up the function from its table:On the C++ side:
And in Lua: