【发布时间】:2019-05-14 13:07:54
【问题描述】:
我正在尝试为 C++ 库创建一个 SWIG Python 接口,为一些函数添加 Python 包装器,非常感谢有 SWIG 经验的人提供的帮助。
目前我有这样的来源:
test.h
namespace Test {
class CodeResponseEvent {
public:
CodeResponseEvent(std::string activation_code);
std::string getActivationCode() const;
private:
const std::string activation_code_;
};
class CodeRequestEvent {
public:
CodeRequestEvent(std::string user_id);
std::shared_ptr<CodeResponseEvent> execute();
private:
const std::string user_id_;
};
}
test.i
%module test
%include std_string.i
%include <std_shared_ptr.i>
%{#include "test.h"%}
%include "test.h"
%shared_ptr(Test::CodeResponseEvent);
Python 代码如下:
codeResponse = test.CodeRequestEvent("user").execute()
结果我得到了价值
<Swig Object of type 'std::shared_ptr< Test::CodeResponseEvent> *'>
那么问题是如何解开这个 SwigPyobject 来调用 getActivationCode() 方法?
【问题讨论】: