mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 10:37:41 -04:00
Add some Python Helpers
We can now convert plString to PyUnicode objects and have static methods with variable arguments and variable keyword arguments
This commit is contained in:
@ -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());
|
||||
}
|
||||
|
@ -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}
|
||||
|
Reference in New Issue
Block a user