将luabind派生成员调用为协同程序
Calling luabind derived member as a coroutine
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
逻辑应该按原样工作。
所以我已经找到了这个问题的答案。似乎最简单的解决方案是在构建对象时从Lua传递self
,然后从其表中查找函数:
在C++方面:
BaseWrapper::BaseWrapper(luabind::object self) : _self(self)
{ }
virtual void BaseWrapper::foo()
{
luabind::object func = _self["foo"];
/* now put func in coroutine scheduler queue and when appropriate call:
luabind::resume_function<void>(func, _self);
*/
}
在卢阿:
class 'Derived' (Base)
function Derived:__init()
Base.__init(self, self) -- the second self is param to BaseWrapper()
end
function Derived:foo()
-- here is the target function
end
end
相关文章:
- C# DLL 从C++应用程序调用 SOAP Web 服务
- 从C++程序调用 git 克隆
- 使用另一个程序调用正在运行的 C++ 程序中的函数
- C++控制台应用程序调用C++/CLI静态库
- 从 C# Windows 应用程序调用 C dll 会导致 svchost.exe 崩溃
- LoadLibray FileNotFound 取决于哪个应用程序调用
- 为什么无法在 Cocoa 应用程序调用的 C++ func 中嵌入自定义 Python 模块
- 使用模拟器C++从RISC-V裸机程序调用printf系统调用时失败
- C++程序调用 C 函数 在 g++ 链接期间获取未定义的引用
- 使用 gtest 和 gmock 验证程序调用
- 从 Qt 小部件应用程序调用 pyqt widget
- 如何使用Mono / C#程序调用Linux / C ++函数?
- 是否可以通过另一个程序调用程序
- 从应用程序调用静态库时,QT创建者什么都不会发生
- 如何知道库的哪些功能是由程序调用的
- OpenCV 函数在由C++线程程序调用的 Python 脚本本身调用时锁定
- numpy.core.multiarray在通过Xcode中开发的C 应用程序调用Python模块时未能导入
- 如何使用 lamba 作为连接处理程序调用 boost async_connect 作为成员函数
- 如何调试由另一个程序调用的程序
- 从C 程序调用FFMPEG