Disclaimer, I am a swig and python noob
I have my own c++ library and I am wrapping it to use in python with swig.
My c++ class is like this:
public MyCppClass()
{
public:
void MyFunction(char* outCharPtr, string& outStr, int& outInt, long& outLong)
{
outCharPtr = new char[2];
outCharPtr[0] = "o";
outCharPtr[1] = "k";
outStr = "This is a result";
outInt = 1;
outLong = (long)12345;
}
}
Now I wrap this class using swig and say the module is called MyClass.
What I want to achieve in python is the following code (OR SAY PSEUDO CODE because if it was the code it would be working) and output:
import module MyClass
from MyClass import MyCppClass
obj = MyCppClass();
outCharPtr = "";
outStr = "";
outInt = 0;
outLong = 0;
obj.MyFunction(outCharPtr, outStr, outInt, outLong);
print(outCharPtr);
print(outStr);
print(outInt);
print(outLong);
The output I want is:
>>>Ok
>>>This is a result
>>>1
>>>12345
I am using python 3.4
I am really apologetic if this is something basic but I have already spent around 8 hours on the resolution and can't come up with anything.
Any help will be very appreciated.
Thanks.
strandintPython objects, so that desired syntax won't work. The objects can't change. What SWIG can do for you is convert C/C++ output parameters to a tuple of return values. For example,outCharPtr,outStr,outInt,outLong = obj.MyFunction().