python - 是否可以在 Pybind11 中将 Python 函数作为 C 风格的函数指针传递?
问题描述
阅读 Pybind11 的文档只能清楚地表明 std::function 用于包装 Python 函数并允许 C++ 调用它但是我需要将 Python 函数作为函数指针传递,这可能吗?据我所知,将 std::function 转换为函数指针是不可能的。例如,将 std::function 回调分配给如下所示的函数指针,或者直接通过 pybind11 传递函数指针:
typedef struct
{
void (*handlerfunc) (int, char const *);
}handler;
在 Pybind11 模块块中,理想情况下我可以这样分配:
m.def("assignStruct",[](const std::function<void(int number, char const * req)> &f2)
{
handler handlerS =
{
f2
}
});
解决方案
推荐阅读
- c# - System.IO 不创建文件 json
- r - 根据 gregexpr 返回的字符位置提取文本
- c++ - 解析浮点数后跟包含“e”字符的字符串
- java - GUI 登录系统在单击确定按钮时没有反应
- c++ - 减去两个整数会导致设备代码中的整数下溢
- r - 是否可以使用 rvest 刮掉课程本身?
- javascript - FAB 组按钮未设置状态 - React Native
- javascript - Javascript 更改所有数组元素的 HTML 代码
- ios - 当我的 iOS 应用程序在后台使用 ReplayKit 时进行屏幕录制
- json - 如何使用 asp.net 核心框架返回带有 2 个对象的 json?