擅长:python、mysql、java
<p>你有没有考虑过使用SWIG carrays?在</p>
<p>文件头中:</p>
<pre><code>typedef struct {
int icntl[40];
double cntl[15];
} some_struct_t;
</code></pre>
<p>然后,在你的swig文件中:</p>
^{pr2}$
<p>Python如下所示:</p>
<pre><code>icntl = example.intArray(40)
cntl = example.doubleArray(15)
for i in range(0, 40):
icntl[i] = i
for i in range(0, 15):
cntl[i] = i
st = example.some_struct_t()
st.icntl = icntl
st.cntl = cntl
</code></pre>
<p>仍然不能直接设置结构。我编写python包装器代码来隐藏样板。在</p>
<p>array_类只适用于基本类型(int、double),如果需要其他类型(例如uint8_t),则需要使用array_函数,这些函数有更多的样板文件,但它们可以工作。在</p>
<p><a href="http://www.swig.org/Doc3.0/SWIGDocumentation.html#Library_carrays" rel="nofollow noreferrer">http://www.swig.org/Doc3.0/SWIGDocumentation.html#Library_carrays</a></p>