mirror of
https://github.com/worldforge/cyphesis
synced 2026-08-13 12:26:04 -04:00
Move core code into Python, making things way more flexible.
This commit is contained in:
parent
994830d6c6
commit
efe75fceac
9 changed files with 40 additions and 49 deletions
|
|
@ -28,8 +28,9 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
int runClientScript(CreatorClient * c, const std::string & package,
|
||||
const std::string & func)
|
||||
int python_client_script(const std::string & package,
|
||||
const std::string & func,
|
||||
const std::map<std::string, std::string> & keywords)
|
||||
{
|
||||
PyObject * module = Get_PyModule(package);
|
||||
if (module == NULL) {
|
||||
|
|
@ -50,13 +51,21 @@ int runClientScript(CreatorClient * c, const std::string & package,
|
|||
Py_DECREF(function);
|
||||
return -1;
|
||||
}
|
||||
PyCreatorClient * editor = newPyCreatorClient();
|
||||
if (editor == NULL) {
|
||||
Py_DECREF(function);
|
||||
return -1;
|
||||
PyObject * args = Py_BuildValue("()");
|
||||
PyObject * kwds = PyDict_New();
|
||||
std::map<std::string, std::string>::const_iterator I = keywords.begin();
|
||||
std::map<std::string, std::string>::const_iterator Iend = keywords.end();
|
||||
for (; I != Iend; ++I) {
|
||||
PyObject * v = PyString_FromString(I->second.c_str());
|
||||
PyDict_SetItemString(kwds, I->first.c_str(), v);
|
||||
Py_DECREF(v);
|
||||
}
|
||||
editor->m_mind = c;
|
||||
PyObject * pyob = PyEval_CallFunction(function, "(O)", editor);
|
||||
PyObject * pyob = PyEval_CallObjectWithKeywords(function,
|
||||
args,
|
||||
kwds);
|
||||
|
||||
Py_DECREF(kwds);
|
||||
Py_DECREF(args);
|
||||
|
||||
if (pyob == NULL) {
|
||||
if (PyErr_Occurred() == NULL) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue