Say I have this simple class and instance:
class MyClass:
def __init__(self, value):
self.value = value
def my_method(self):
return self.value * 2
my_object = MyClass(1)
Is it possible to pass my_object directly to C using ctypes or any other module? If I'm able to get at least the attributes of my_object in C I will be happy, but better If I could get the methods and be able to call them it within C.
I'm currently doing:
import ctypes
my_library = ctypes.CDLL('my_library.so')
my_library.my_c_function.argtypes = [ctypes.c_int]
my_library.my_c_function.restype = ctypes.c_int
my_object_c_value = ctypes.c_int(my_object.value)
my_library.my_c_function(my_object_c_value)
And doing this for every attribute inside my_object. This get's very repetitive when the class has too many attributes.
I tried reading the documentation on ctypes but It's too technical, and incomprehensive for me.