2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-20 16:52:15 +00:00

embedding tutorial updates

[SVN r22616]
This commit is contained in:
Joel de Guzman
2004-04-07 02:26:36 +00:00
parent 7d632ab3dd
commit b627f93cf1
10 changed files with 218 additions and 101 deletions

View File

@@ -132,6 +132,40 @@ test_tutorial()
);
}
void
test_tutorial2()
{
using namespace boost::python;
object main_module(
handle<>(borrowed(PyImport_AddModule("__main__"))));
dict main_namespace(
handle<>(borrowed(PyModule_GetDict(main_module.ptr()))));
handle<>(PyRun_String(
"result = 5 ** 2"
, Py_file_input
, main_namespace.ptr()
, main_namespace.ptr())
);
int five_squared = extract<int>(main_namespace["result"]);
assert(five_squared == 25);
object result(handle<>(
PyRun_String("5 ** 2"
, Py_eval_input
, main_namespace.ptr()
, main_namespace.ptr()))
);
int five_squared2 = extract<int>(result);
assert(five_squared2 == 25);
}
int main()
{
if (python::handle_exception(test))
@@ -148,6 +182,13 @@ int main()
return 1;
}
if (python::handle_exception(test_tutorial2))
{
if (PyErr_Occurred())
PyErr_Print();
return 1;
}
return 0;
}
#include "module_tail.cpp"