diff --git a/Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.cpp b/Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.cpp index 69bedc17..5cd5f14d 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.cpp @@ -62,3 +62,9 @@ bool PyString_CheckEx(PyObject* obj) { return (PyString_Check(obj) || PyUnicode_Check(obj)); } + +PyObject* PyUnicode_FromStringEx(const plString& str) +{ + plStringBuffer buf = str.ToWchar(); + return PyUnicode_FromWideChar(buf.GetData(), buf.GetSize()); +} diff --git a/Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.h b/Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.h index 61d0292b..5f85c14a 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.h +++ b/Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.h @@ -49,6 +49,7 @@ class plString; plString PyString_AsStringEx(PyObject* obj); bool PyString_CheckEx(PyObject* obj); +PyObject* PyUnicode_FromStringEx(const plString& str); // A set of macros to take at least some of the tediousness out of creating straight python glue code @@ -353,6 +354,10 @@ PyModule_AddObject(m, #pythonClassName, (PyObject*)&pythonClassName##_type) static PyObject *pythonClassName##_##methodName(pythonClassName *self, PyObject *argsVar) #define PYTHON_METHOD_DEFINITION_NOARGS(pythonClassName, methodName) \ static PyObject *pythonClassName##_##methodName(pythonClassName *self) +#define PYTHON_METHOD_DEFINITION_STATIC(pythonClassName, methodName, argsVar) \ + static PyObject *pythonClassName##_##methodName(PyObject*, PyObject *argsVar) +#define PYTHON_METHOD_DEFINITION_STATIC_WKEY(pythonClassName, methodName, argsVar, keywordsVar) \ + static PyObject *pythonClassName##_##methodName(PyObject*, PyObject *argsVar, PyObject *keywordsVar) #define PYTHON_METHOD_DEFINITION_WKEY(pythonClassName, methodName, argsVar, keywordsVar) \ static PyObject *pythonClassName##_##methodName(pythonClassName *self, PyObject *argsVar, PyObject *keywordsVar) @@ -390,6 +395,14 @@ static PyObject *pythonClassName##_##methodName(pythonClassName *self) \ #define PYTHON_METHOD_NOARGS(pythonClassName, methodName, docString) \ {#methodName, (PyCFunction)pythonClassName##_##methodName, METH_NOARGS, docString} +// static method with arguments +#define PYTHON_METHOD_STATIC(pythonClassName, methodName, docString) \ + {#methodName, (PyCFunction)pythonClassName##_##methodName, METH_STATIC | METH_VARARGS, docString} + +// static method with keywords +#define PYTHON_METHOD_STATIC_WKEY(pythonClassName, methodName, docString) \ + {#methodName, (PyCFunction)pythonClassName##_##methodName, METH_STATIC | METH_VARARGS | METH_KEYWORDS, docString} + // method with keywords #define PYTHON_METHOD_WKEY(pythonClassName, methodName, docString) \ {#methodName, (PyCFunction)pythonClassName##_##methodName, METH_VARARGS | METH_KEYWORDS, docString}