Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-06-16 11:16:51 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-06-16 11:16:51 +0400
commit2ecbe1c81cec6f537aa10829e94fbc451f9bc823 (patch)
treefeba81632819f672cc62b118b5f73e2e2193d2cf /source/gameengine/Ketsji/KX_PythonInit.cpp
parent6efd2e643953b293aaf7ef0de50d08badd2f49a8 (diff)
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
Diffstat (limited to 'source/gameengine/Ketsji/KX_PythonInit.cpp')
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index b10ea7e1ab5..75b29481e54 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -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';
}