00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #include <game.h>
00024 #include <iostream>
00025
00032 extern "C" void initpyIrr();
00033 extern "C" void initpyMerry();
00034
00036 pyInt::pyInt() : base("pyInt")
00037 {
00038
00039 }
00040
00042 pyInt::~pyInt()
00043 {
00044
00045 }
00046
00050 int pyInt::init(coeur* c)
00051 {
00052
00053 base::init(0,c);
00054
00055
00056 char modIrr[] = "pyIrr";
00057 char modMerry[] = "pyMerry";
00058 PyImport_AppendInittab(modIrr, initpyIrr);
00059 PyImport_AppendInittab(modMerry, initpyMerry);
00060 Py_Initialize();
00061 main_module = import("__main__");
00062 dict = main_module.attr("__dict__");
00063 exec("from pyIrr import *");
00064 exec("from pyMerry import *");
00065 addPyEnv("core",object(ptr(c)));
00066
00067 return 0;
00068 }
00069
00072 int pyInt::update()
00073 {
00074 return 0;
00075 }
00076
00079 int pyInt::close()
00080 {
00081 Py_Finalize();
00082 return base::close();
00083 }
00084
00089 bool pyInt::OnEvent(const SEvent& event)
00090 {
00091 return false;
00092 }
00093
00097 stringw pyInt::eval(stringw str)
00098 {
00099 object r;
00100 try
00101 {
00102 r = boost::python::exec(stringc(str).c_str(),dict,dict);
00103 }
00104 catch (...)
00105 {
00106 PyErr_Print();
00107 log(stringc("Error in the command ") + str);
00108 return stringw(L"Error in the command : ") + str + "\n";
00109 }
00110
00111
00112 log(stringc("Run(exec) succesfully the command ") + str);
00113 return stringc("");
00114 }
00115
00119 int pyInt::exec(stringw str)
00120 {
00121 try
00122 {
00123 boost::python::exec(stringc(str).c_str(),dict,dict);
00124 }
00125 catch (...)
00126 {
00127 log(stringc("Error in the script") + str);
00128 return -1;
00129 }
00130 log(stringc("Run succesfully the script\n###################\n") + str + "\n###################\n");
00131 return 0;
00132 }
00133
00138 int pyInt::addPyEnv(stringc s,object o)
00139 {
00140 main_module.attr(s.c_str()) = o;
00141 return 0;
00142 }
00143
00144