This is my SWIG typemap:
%apply (float *INOUT, int) {(float *io1, int n1)};
%apply (float *INOUT, int) {(float *io2, int n2)};
And This is my function:
void process(float *io1, int n1, float *io2, int n2)
{
for (int i = 0; i < n1; ++i)
{
io1[i] = io1[i] * 0.1;
io2[i] = io2[i] * 0.1;
}
}
I expect the process function to take 2 tables and return 2 tables.
In Lua, the process function seems to return 2 tables but it only returns the same 2 tables which is passed from the first argument.
For example In Lua, when I run the following:
local a, b = {3}, {4}
local c, d = process(a, b)
print(c[1], d[1])
The result I get:
0.3 0.3
But I expect:
0.3 0.4
How should I change the SWIG typemap to make it work as expected?
I cannot reproduce your problem with the following minimal example.
test.itest.htest.ctest.luaThen I compile and run using
The garbage values after the 7th decimal digit stem from the promotion of
floattolua_Numberwhich isdoubleby default.Disregarding this, I see the expected
0.3 0.4. That means the error must be in some code that you have not shown. Make sure to%applythe typemaps before parsing the prototype ofprocess, i.e. in the example above note how%applycomes before%include "test.h".