Browse Source

Add some Python Helpers

We can now convert plString to PyUnicode objects and have static methods
with variable arguments and variable keyword arguments
Adam Johnson 12 years ago
parent
commit
8e79583717
  1. 6
      Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.cpp
  2. 13
      Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.h

6
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<wchar_t> buf = str.ToWchar();
return PyUnicode_FromWideChar(buf.GetData(), buf.GetSize());
}

13
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}

Loading…
Cancel
Save