|
|
@ -49,6 +49,23 @@ PYTHON_CLASS_DEFINITION(ptPlayer, pyPlayer); |
|
|
|
PYTHON_DEFAULT_NEW_DEFINITION(ptPlayer, pyPlayer) |
|
|
|
PYTHON_DEFAULT_NEW_DEFINITION(ptPlayer, pyPlayer) |
|
|
|
PYTHON_DEFAULT_DEALLOC_DEFINITION(ptPlayer) |
|
|
|
PYTHON_DEFAULT_DEALLOC_DEFINITION(ptPlayer) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static char* ConvertString(PyObject* obj) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (PyString_Check(obj)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return hsStrcpy(PyString_AsString(obj)); |
|
|
|
|
|
|
|
} else if (PyUnicode_Check(obj)) { |
|
|
|
|
|
|
|
size_t size = PyUnicode_GetSize(obj); |
|
|
|
|
|
|
|
wchar_t* temp = new wchar_t[size + 1]; |
|
|
|
|
|
|
|
PyUnicode_AsWideChar((PyUnicodeObject*)obj, temp, size); |
|
|
|
|
|
|
|
temp[size] = 0; |
|
|
|
|
|
|
|
char* buf = hsWStringToString(temp); |
|
|
|
|
|
|
|
delete[] temp; |
|
|
|
|
|
|
|
return buf; |
|
|
|
|
|
|
|
} else |
|
|
|
|
|
|
|
return NULL; // You suck.
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PYTHON_INIT_DEFINITION(ptPlayer, args, keywords) |
|
|
|
PYTHON_INIT_DEFINITION(ptPlayer, args, keywords) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// we have two sets of arguments we can use, hence the generic PyObject* pointers
|
|
|
|
// we have two sets of arguments we can use, hence the generic PyObject* pointers
|
|
|
@ -63,56 +80,46 @@ PYTHON_INIT_DEFINITION(ptPlayer, args, keywords) |
|
|
|
PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)"); |
|
|
|
PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)"); |
|
|
|
PYTHON_RETURN_INIT_ERROR; |
|
|
|
PYTHON_RETURN_INIT_ERROR; |
|
|
|
} |
|
|
|
} |
|
|
|
if (pyKey::Check(firstObj)) // arg set 1
|
|
|
|
|
|
|
|
|
|
|
|
pyKey* key = NULL; |
|
|
|
|
|
|
|
char* name = NULL; |
|
|
|
|
|
|
|
uint32_t pid = -1; |
|
|
|
|
|
|
|
float distSeq = -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (pyKey::Check(firstObj)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// make sure the remaining objects fit the arg list
|
|
|
|
key = pyKey::ConvertFrom(firstObj); |
|
|
|
if ((!thirdObj) || (!fourthObj)) |
|
|
|
if (!(name = ConvertString(secondObj))) |
|
|
|
{ |
|
|
|
|
|
|
|
// missing arguments
|
|
|
|
|
|
|
|
PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)"); |
|
|
|
|
|
|
|
PYTHON_RETURN_INIT_ERROR; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if ((!PyString_Check(secondObj)) || (!PyLong_Check(thirdObj)) || (!PyFloat_Check(fourthObj))) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// incorrect types
|
|
|
|
|
|
|
|
PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)"); |
|
|
|
PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)"); |
|
|
|
PYTHON_RETURN_INIT_ERROR; |
|
|
|
PYTHON_RETURN_INIT_ERROR; |
|
|
|
} |
|
|
|
} |
|
|
|
// all args are correct, convert and init
|
|
|
|
if (!(PyLong_Check(thirdObj) && PyFloat_Check(fourthObj))) |
|
|
|
pyKey* key = pyKey::ConvertFrom(firstObj); |
|
|
|
|
|
|
|
char* name = PyString_AsString(secondObj); |
|
|
|
|
|
|
|
unsigned long pid = PyLong_AsUnsignedLong(thirdObj); |
|
|
|
|
|
|
|
float distsq = (float)PyFloat_AsDouble(fourthObj); |
|
|
|
|
|
|
|
self->fThis->Init(key->getKey(), name, pid, distsq); |
|
|
|
|
|
|
|
PYTHON_RETURN_INIT_OK; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (PyString_Check(firstObj)) // arg set 2
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// make sure there are only two args
|
|
|
|
|
|
|
|
if (thirdObj || fourthObj) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// too many arguments
|
|
|
|
delete[] name; |
|
|
|
PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)"); |
|
|
|
PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)"); |
|
|
|
PYTHON_RETURN_INIT_ERROR; |
|
|
|
PYTHON_RETURN_INIT_ERROR; |
|
|
|
} |
|
|
|
} |
|
|
|
char* name = PyString_AsString(firstObj); |
|
|
|
|
|
|
|
unsigned long pid = 0; |
|
|
|
pid = PyLong_AsUnsignedLong(thirdObj); |
|
|
|
if (PyLong_Check(secondObj)) |
|
|
|
distSeq = (float)PyFloat_AsDouble(fourthObj); |
|
|
|
pid = PyLong_AsUnsignedLong(secondObj); |
|
|
|
} else if (name = ConvertString(firstObj)){ |
|
|
|
else if (PyInt_Check(secondObj)) |
|
|
|
if (!PyLong_Check(secondObj) || thirdObj || fourthObj) |
|
|
|
pid = (unsigned long)PyInt_AsLong(secondObj); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// incorrect type
|
|
|
|
delete[] name; |
|
|
|
PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)"); |
|
|
|
PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)"); |
|
|
|
PYTHON_RETURN_INIT_ERROR; |
|
|
|
PYTHON_RETURN_INIT_ERROR; |
|
|
|
} |
|
|
|
} |
|
|
|
self->fThis->Init(nil, name, pid, -1); |
|
|
|
|
|
|
|
PYTHON_RETURN_INIT_OK; |
|
|
|
pid = PyLong_AsUnsignedLong(secondObj); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)"); |
|
|
|
|
|
|
|
PYTHON_RETURN_INIT_ERROR; |
|
|
|
} |
|
|
|
} |
|
|
|
// some other args came in
|
|
|
|
|
|
|
|
PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)"); |
|
|
|
self->fThis->Init(key, name, pid, distSeq); |
|
|
|
PYTHON_RETURN_INIT_ERROR; |
|
|
|
delete[] name; |
|
|
|
|
|
|
|
PYTHON_RETURN_INIT_OK; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PYTHON_RICH_COMPARE_DEFINITION(ptPlayer, obj1, obj2, compareType) |
|
|
|
PYTHON_RICH_COMPARE_DEFINITION(ptPlayer, obj1, obj2, compareType) |
|
|
|