Browse Source

Merge pull request #349 from Hoikas/debug-print

Port PtDebugPrint to C++
Adam Johnson 11 years ago
parent
commit
cbfa49d71c
  1. 27
      Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp
  2. 1
      Sources/Plasma/FeatureLib/pfPython/cyMisc.h
  3. 35
      Sources/Plasma/FeatureLib/pfPython/cyMiscGlue4.cpp

27
Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp

@ -2599,6 +2599,33 @@ void cyMisc::DebugAssert( bool cond, const char * msg )
hsAssert( cond, msg );
}
void cyMisc::DebugPrint(const plString& msg, uint32_t level)
{
if (level < fPythonLoggingLevel)
return;
plStatusLog* log = plStatusLogMgr::GetInstance().FindLog("python.log", false);
if (!log)
return;
switch (level) {
case kDebugDump:
log->AddLine(msg.c_str(), plStatusLog::kGreen);
break;
case kWarningLevel:
log->AddLine(msg.c_str(), plStatusLog::kYellow);
break;
case kAssertLevel:
hsAssert(false, msg.c_str());
// ... fall thru to the actual log-print
case kErrorLevel:
log->AddLine(msg.c_str(), plStatusLog::kRed);
break;
default:
log->AddLine(msg.c_str(), plStatusLog::kWhite);
break;
}
}
//////////////////////////////////////////////////////////////////////////////
//
// Function : Set a python object to be called back after a certain amount of time.

1
Sources/Plasma/FeatureLib/pfPython/cyMisc.h

@ -853,6 +853,7 @@ public:
// PURPOSE : debugging
//
static void DebugAssert( bool cond, const char * msg );
static void DebugPrint(const plString& msg, uint32_t level);
//////////////////////////////////////////////////////////////////////////////

35
Sources/Plasma/FeatureLib/pfPython/cyMiscGlue4.cpp

@ -416,6 +416,40 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtDebugAssert, args, "Params: cond, msg\nDebug o
PYTHON_RETURN_NONE;
}
PYTHON_GLOBAL_METHOD_DEFINITION_WKEY(PtDebugPrint, args, kwargs, "Params: *msgs, **kwargs\nPrints msgs to the Python log given the message's level")
{
uint32_t level = cyMisc::kErrorLevel;
do {
// Grabbin' levelz
if (kwargs && PyDict_Check(kwargs)) {
PyObject* value = PyDict_GetItem(kwargs, PyString_FromString("level"));
if (value) {
if (PyInt_Check(value))
level = PyInt_AsLong(value);
else
break;
}
}
for (size_t i = 0; i < PySequence_Fast_GET_SIZE(args); ++i) {
PyObject* theMsg = PySequence_Fast_GET_ITEM(args, i);
if (!PyString_CheckEx(theMsg))
theMsg = PyObject_Repr(theMsg);
if (theMsg)
cyMisc::DebugPrint(PyString_AsStringEx(theMsg), level);
else
break;
}
PYTHON_RETURN_NONE;
} while (false);
// fell through to the type error case
PyErr_SetString(PyExc_TypeError, "PtDebugPrint expects a sequence of strings and an optional int");
PYTHON_RETURN_ERROR;
}
PYTHON_GLOBAL_METHOD_DEFINITION(PtSetAlarm, args, "Params: secs, cbObject, cbContext\nsecs is the amount of time before your alarm goes off.\n"
"cbObject is a python object with the method onAlarm(int context)\ncbContext is an integer.")
{
@ -812,6 +846,7 @@ void cyMisc::AddPlasmaMethods4(std::vector<PyMethodDef> &methods)
PYTHON_GLOBAL_METHOD(methods, PtSetGlobalClickability);
PYTHON_GLOBAL_METHOD(methods, PtDebugAssert);
PYTHON_GLOBAL_METHOD(methods, PtDebugPrint);
PYTHON_GLOBAL_METHOD(methods, PtSetAlarm);
PYTHON_GLOBAL_METHOD(methods, PtSaveScreenShot);

Loading…
Cancel
Save