2
3
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-14 10:37:41 -04:00

ptStatusLog now supports unicode objects and string objects

This commit is contained in:
2012-02-04 17:57:22 -05:00
parent 383ef67790
commit e2b9bba70c
2 changed files with 19 additions and 9 deletions

View File

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

View File

@ -58,21 +58,31 @@ PYTHON_INIT_DEFINITION(ptStatusLog, args, keywords)
PYTHON_METHOD_DEFINITION(ptStatusLog, open, args)
{
char* logName;
PyObject* logName;
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");
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)
{
char* text;
PyObject* text;
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");
PYTHON_RETURN_ERROR;
@ -85,9 +95,9 @@ PYTHON_METHOD_DEFINITION(ptStatusLog, write, args)
PYTHON_RETURN_ERROR;
}
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);