BGE Py API
* Removed modules Expression and CValue, neither were ever available. * Added GameLogic.EvalExpression(exp) from the Expression module, evaluates an expression like the expression controller (not sure if this is really that useful since python is far more advanced). * resetting the original blend file path didint work (own fault == -> =) * Py3.x PyModule_Create didnt allow importing since it didn't add to sys.modules, Looks like they want us to use init-tab array, but this doesn't suit us since it needs to be setup before python is initialized. * Documented GameLogic.globalDict
This commit is contained in:
@@ -70,6 +70,7 @@
|
||||
#include "MT_Vector3.h"
|
||||
#include "MT_Point3.h"
|
||||
#include "ListValue.h"
|
||||
#include "InputParser.h"
|
||||
#include "KX_Scene.h"
|
||||
#include "SND_DeviceManager.h"
|
||||
|
||||
@@ -498,6 +499,32 @@ static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *)
|
||||
}
|
||||
|
||||
|
||||
static PyObject *gEvalExpression(PyObject*, PyObject* value)
|
||||
{
|
||||
char* txt= PyString_AsString(value);
|
||||
|
||||
if (txt==NULL) {
|
||||
PyErr_SetString(PyExc_TypeError, "Expression.calc(text): expects a single string argument");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CParser parser;
|
||||
CExpression* expr = parser.ProcessText(txt);
|
||||
CValue* val = expr->Calculate();
|
||||
expr->Release();
|
||||
|
||||
if (val) {
|
||||
PyObject* pyobj = val->ConvertValueToPython();
|
||||
if (pyobj)
|
||||
return pyobj;
|
||||
else
|
||||
return val->GetProxy();
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
static struct PyMethodDef game_methods[] = {
|
||||
{"expandPath", (PyCFunction)gPyExpandPath, METH_VARARGS, (PY_METHODCHAR)gPyExpandPath_doc},
|
||||
{"sendMessage", (PyCFunction)gPySendMessage, METH_VARARGS, (PY_METHODCHAR)gPySendMessage_doc},
|
||||
@@ -526,6 +553,7 @@ static struct PyMethodDef game_methods[] = {
|
||||
{"getAverageFrameRate", (PyCFunction) gPyGetAverageFrameRate, METH_NOARGS, (PY_METHODCHAR)"Gets the estimated average frame rate"},
|
||||
{"getBlendFileList", (PyCFunction)gPyGetBlendFileList, METH_VARARGS, (PY_METHODCHAR)"Gets a list of blend files in the same directory as the current blend file"},
|
||||
{"PrintGLInfo", (PyCFunction)pyPrintExt, METH_NOARGS, (PY_METHODCHAR)"Prints GL Extension Info"},
|
||||
{"EvalExpression", (PyCFunction)gEvalExpression, METH_O, (PY_METHODCHAR)"Evaluate a string as a game logic expression"},
|
||||
{NULL, (PyCFunction) NULL, 0, NULL }
|
||||
};
|
||||
|
||||
@@ -1032,6 +1060,7 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack
|
||||
// Create the module and add the functions
|
||||
#if (PY_VERSION_HEX >= 0x03000000)
|
||||
m = PyModule_Create(&GameLogic_module_def);
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), GameLogic_module_def.m_name, m);
|
||||
#else
|
||||
m = Py_InitModule4("GameLogic", game_methods,
|
||||
GameLogic_module_documentation,
|
||||
@@ -1697,6 +1726,7 @@ PyObject* initRasterizer(RAS_IRasterizer* rasty,RAS_ICanvas* canvas)
|
||||
// Create the module and add the functions
|
||||
#if (PY_VERSION_HEX >= 0x03000000)
|
||||
m = PyModule_Create(&Rasterizer_module_def);
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), Rasterizer_module_def.m_name, m);
|
||||
#else
|
||||
m = Py_InitModule4("Rasterizer", rasterizer_methods,
|
||||
Rasterizer_module_documentation,
|
||||
@@ -1831,6 +1861,7 @@ PyObject* initGameKeys()
|
||||
// Create the module and add the functions
|
||||
#if (PY_VERSION_HEX >= 0x03000000)
|
||||
m = PyModule_Create(&GameKeys_module_def);
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), GameKeys_module_def.m_name, m);
|
||||
#else
|
||||
m = Py_InitModule4("GameKeys", gamekeys_methods,
|
||||
GameKeys_module_documentation,
|
||||
@@ -2106,5 +2137,5 @@ void setGamePythonPath(char *path)
|
||||
// engine but loading blend files within the BGE wont overwrite gp_GamePythonPathOrig
|
||||
void resetGamePythonPath()
|
||||
{
|
||||
gp_GamePythonPathOrig[0] == '\0';
|
||||
gp_GamePythonPathOrig[0] = '\0';
|
||||
}
|
||||
|
Reference in New Issue
Block a user