Parse arguments: no args & Vector object args work, tuples and bare numerics still do not

This commit is contained in:
John McCardle 2024-03-30 22:51:55 -04:00
parent 1c12e8719c
commit 8871f6be6e
1 changed files with 9 additions and 3 deletions

View File

@ -55,16 +55,22 @@ int PyVector::init(PyVectorObject* self, PyObject* args, PyObject* kwds)
{
using namespace mcrfpydef;
static const char* keywords[] = { "x", "y", nullptr };
PyObject* leader;
PyObject* leader = NULL;
double x=0, y=0;
if (!PyArg_ParseTupleAndKeywords, args, kwds, "|Of", leader, &y)
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Of", const_cast<char**>(keywords), &leader, &y))
{
//PyErr_SetString(PyExc_TypeError, "mcrfpy.Vector requires a 2-tuple or two numeric values");
self->data = sf::Vector2f();
return 0;
}
else if (leader == NULL || leader == Py_None)
{
self->data = sf::Vector2f();
return 0;
}
// if the "r" arg is already a vector, yoink that color value
if (PyObject_IsInstance(leader, (PyObject*)&PyVectorType))
else if (PyObject_IsInstance(leader, (PyObject*)&PyVectorType))
{
self->data = ((PyVectorObject*)leader)->data;
return 0;