bazaar: BoostPyTest: invoke py scripts from outside and access upp from inside py scripts

git-svn-id: svn://ultimatepp.org/upp/trunk@3430 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
kohait 2011-05-17 12:31:02 +00:00
parent 890f88d898
commit 478f0a675f
3 changed files with 36 additions and 0 deletions

View file

@ -3,6 +3,12 @@
//CAUTION special module definitions to reduce compile time
#include "modules.cppi"
String GetDataDir()
{
String s = GetEnv("UPP_MAIN__");
return s.GetCount() ? s : GetFileFolder(GetExeFilePath());
}
void BoostPyTest::CBi(int i)
{
RLOG(i);
@ -38,6 +44,12 @@ BoostPyTest::BoostPyTest()
object main_module(handle<>(borrowed(PyImport_AddModule("__main__"))));
main_namespace = main_module.attr("__dict__");
//add path
String s = GetDataDir();
object sys = import("sys");
object path = sys.attr("path");
path.attr("append")(s.Begin());
handle<> ign(PyRun_String( "print \"Hello, World\"",
Py_file_input,
main_namespace.ptr(),
@ -173,6 +185,12 @@ BoostPyTest::BoostPyTest()
"print mu.vir(8)\n"
"print hello.invworld(mu,7)\n"
"import fibo\n"
"fibo.fib(200)\n"
"import myupp\n"
"myupp.chtitle()\n"
;
con.cmd.SetData(sc);