'Extension type instance inside CPython extension type
I have the following extension types in C
//VECTOR 3
typedef struct
{
PyObject_HEAD
double x;
double y;
double z;
}Vec3Object;
static PyMemberDef Vec3Object_Members[]=
{
{"x", T_DOUBLE, offsetof(Vec3Object, x), 0, "X component"},
{"y", T_DOUBLE, offsetof(Vec3Object, y), 0, "Y component"},
{"z", T_DOUBLE, offsetof(Vec3Object, z), 0, "Z component"},
{NULL}
};
//TRANSFORMATIONS
typedef struct
{
PyObject_HEAD
Vec3Object position;
Vec3Object rotation;
Vec3Object scale;
}TransformObject;
//ENTITY
typedef struct
{
PyObject_HEAD
TransformObject transform;
}EntityObject;
And the following PyTypeObject(its also the same for the others and their respective members):
static PyTypeObject TransformObject_Type=
{
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "scene.Transform",
.tp_doc = "Transform type",
.tp_basicsize = sizeof (TransformObject),
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_new = PyType_GenericNew,
.tp_members = TransformObject_Members,
};
Creating a Vec3 works fine but how would a PyMemberDef for TransformObject and EntityObject be defined?
I basically want to call the following Python code:
entity.transform.position.x = 12.5
entity.transform.rotation.y = -74.0
Or the following methods once in a PyMethodDef:
Vec3.Length(entity.transform.position)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
