I would like to have a method in C++ that returns an array of uint8_t, and then using SWIG make the function available in python as a list, something like:
class MyClass
{
uint8_t array_return() {
uint8_t random_array[100];
return random_array;
}
};
and then in Python:
object = MyClass
my_list = object.array_return()
I am quite new to SWIG, and not super proficient in C++, and other issues on stack overflow didn't seem to be working.
How to convert a C++ array to a Python list using SWIG? This answer didn't seem to be working (using std::vector)
Also tried mapping directly in the .i file:
%typemap(out) uint8_t *array_return %{
$result = PyList_New(100);
for (int i = 0; i < 100; ++i) {
PyList_SetItem($result, i, PyFloat_FromDouble($1[i]));
}
%}
In the end I would always get a SwigPyObject and it would not be subscriptable/iterable