static PyObject* tp_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { SELF self; PySoy_bodies_Body_Object* py_bodyA; PySoy_bodies_Body_Object* py_bodyB; PySoy_materials_Material_Object* py_material = NULL; soyscenesScene* scene; soybodiesBody* bodyB; soymaterialsMaterial* material; static char* kw[] = {"bodyA", "bodyB", "material", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O|O!", kw, &PySoy_bodies_Body_Type, &py_bodyA, &py_bodyB, &PySoy_materials_Material_Type, &py_material)) return NULL; // When bodyB is a Body if (PyObject_TypeCheck(py_bodyB, &PySoy_bodies_Body_Type)) { scene = py_bodyB->g->scene; bodyB = py_bodyB->g; } // When bodyB is a Scene else if (PyObject_TypeCheck(py_bodyB, &PySoy_scenes_Scene_Type)) { scene = ((PySoy_scenes_Scene_Object*) py_bodyB)->g; bodyB = NULL; } // Otherwise raise exception else { PyErr_SetString(PyExc_ValueError, "Second argument must be a Body or Scene"); return NULL; } // Ensure bodies are in the same scene if (py_bodyA->g->scene != scene) { PyErr_SetString(PyExc_ValueError, "Scene mismatch"); return NULL; } // Grab material material = (py_material) ? py_material->g : NULL; // Inherit base type self = (SELF) PyType_GenericNew(type, args, NULL); if(!self) return NULL; // Create gobject and return self->g = soy_joints_fixed_new(py_bodyA->g, bodyB, material); return (PyObject*) self; }
static PyObject* tp_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { SELF self; soyscenesScene* scene; PySoy_scenes_Scene_Object* pyscene; PySoy_bodies_Body_Object* bodyOne; PySoy_bodies_Body_Object* bodyTwo; if (PyArg_ParseTuple(args, "O!O!", &PySoy_bodies_Body_Type, &bodyOne, &PySoy_bodies_Body_Type, &bodyTwo)) scene = bodyTwo->g->scene; else { PyErr_Clear(); if (PyArg_ParseTuple(args, "O!O!", &PySoy_bodies_Body_Type, &bodyOne, &PySoy_scenes_Scene_Type, &pyscene)) scene = pyscene->g; else return NULL; } // Ensure bodies are in the same scene if (bodyOne->g->scene != scene) { PyErr_SetString(PyExc_ValueError, "Bodies must be in the same scene"); return NULL; } self = (SELF) PyType_GenericNew(type, args, NULL); if(!self) return NULL; if(!bodyTwo) self->g = soy_joints_fixed_new(scene, bodyOne->g, NULL, NULL); else self->g = soy_joints_fixed_new(scene, bodyOne->g, bodyTwo->g, NULL); return (PyObject*) self; }