diff --git a/bazaar/BoostPyTest/fibo.py b/bazaar/BoostPyTest/fibo.py new file mode 100644 index 000000000..8123d0049 --- /dev/null +++ b/bazaar/BoostPyTest/fibo.py @@ -0,0 +1,15 @@ +# Fibonacci numbers module + +def fib(n): # write Fibonacci series up to n + a, b = 0, 1 + while b < n: + print b, + a, b = b, a+b + +def fib2(n): # return Fibonacci series up to n + result = [] + a, b = 0, 1 + while b < n: + result.append(b) + a, b = b, a+b + return result diff --git a/bazaar/BoostPyTest/main.cpp b/bazaar/BoostPyTest/main.cpp index 8ded4dc96..fc5e5aa69 100644 --- a/bazaar/BoostPyTest/main.cpp +++ b/bazaar/BoostPyTest/main.cpp @@ -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); diff --git a/bazaar/BoostPyTest/myupp.py b/bazaar/BoostPyTest/myupp.py new file mode 100644 index 000000000..d8b76d5be --- /dev/null +++ b/bazaar/BoostPyTest/myupp.py @@ -0,0 +1,3 @@ +import upp; +def chtitle(): + upp.app.title = "The title was changed from outside :)"