Browse Source

ptStatusLog now supports unicode objects and string objects

Adam Johnson 13 years ago
parent
commit
e2b9bba70c
  1. 4
      Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.h
  2. 24
      Sources/Plasma/FeatureLib/pfPython/pyStatusLogGlue.cpp

4
Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.h

@ -45,8 +45,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <Python.h> #include <Python.h>
// Useful string functions // Useful string functions
char* PyString_AsStringEx(PyObject*); char* PyString_AsStringEx(PyObject* obj);
inline bool PyString_CheckEx(PyObject*); bool PyString_CheckEx(PyObject* obj);
// A set of macros to take at least some of the tediousness out of creating straight python glue code // A set of macros to take at least some of the tediousness out of creating straight python glue code

24
Sources/Plasma/FeatureLib/pfPython/pyStatusLogGlue.cpp

@ -58,21 +58,31 @@ PYTHON_INIT_DEFINITION(ptStatusLog, args, keywords)
PYTHON_METHOD_DEFINITION(ptStatusLog, open, args) PYTHON_METHOD_DEFINITION(ptStatusLog, open, args)
{ {
char* logName; PyObject* logName;
unsigned long numLines, flags; unsigned long numLines, flags;
if (!PyArg_ParseTuple(args, "sll", &logName, &numLines, &flags)) if (!PyArg_ParseTuple(args, "Oll", &logName, &numLines, &flags))
{ {
PyErr_SetString(PyExc_TypeError, "open expects a string and two unsigned longs"); PyErr_SetString(PyExc_TypeError, "open expects a string and two unsigned longs");
PYTHON_RETURN_ERROR; PYTHON_RETURN_ERROR;
} }
PYTHON_RETURN_BOOL(self->fThis->Open(logName, numLines, flags)); if (!PyString_CheckEx(logName))
{
PyErr_SetString(PyExc_TypeError, "open expects a string and two unsigned longs");
PYTHON_RETURN_ERROR;
}
PYTHON_RETURN_BOOL(self->fThis->Open(PyString_AsStringEx(logName), numLines, flags));
} }
PYTHON_METHOD_DEFINITION(ptStatusLog, write, args) PYTHON_METHOD_DEFINITION(ptStatusLog, write, args)
{ {
char* text; PyObject* text;
PyObject* colorObj = NULL; PyObject* colorObj = NULL;
if (!PyArg_ParseTuple(args, "s|O", &text, &colorObj)) if (!PyArg_ParseTuple(args, "O|O", &text, &colorObj))
{
PyErr_SetString(PyExc_TypeError, "write expects a string and an optional ptColor");
PYTHON_RETURN_ERROR;
}
if (!PyString_CheckEx(text))
{ {
PyErr_SetString(PyExc_TypeError, "write expects a string and an optional ptColor"); PyErr_SetString(PyExc_TypeError, "write expects a string and an optional ptColor");
PYTHON_RETURN_ERROR; PYTHON_RETURN_ERROR;
@ -85,9 +95,9 @@ PYTHON_METHOD_DEFINITION(ptStatusLog, write, args)
PYTHON_RETURN_ERROR; PYTHON_RETURN_ERROR;
} }
pyColor* color = pyColor::ConvertFrom(colorObj); pyColor* color = pyColor::ConvertFrom(colorObj);
PYTHON_RETURN_BOOL(self->fThis->WriteColor(text, *color)); PYTHON_RETURN_BOOL(self->fThis->WriteColor(PyString_AsStringEx(text), *color));
} }
PYTHON_RETURN_BOOL(self->fThis->Write(text)); PYTHON_RETURN_BOOL(self->fThis->Write(PyString_AsStringEx(text)));
} }
PYTHON_BASIC_METHOD_DEFINITION(ptStatusLog, close, Close); PYTHON_BASIC_METHOD_DEFINITION(ptStatusLog, close, Close);

Loading…
Cancel
Save