Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // StacklessPythonCppInterop.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <boost/python.hpp>
- #include "TimeBomb.hpp"
- using namespace boost;
- using namespace boost::python;
- BOOST_PYTHON_MODULE(kaboom)
- {
- class_<ITimeBombCallbackWrapper, boost::shared_ptr<ITimeBombCallbackWrapper>, boost::noncopyable>("ITimeBombCallback")
- .def("ReceiveExplosion", pure_virtual(&ITimeBombCallback::ReceiveExplosion))
- ;
- class_<TimeBomb>("TimeBomb", init<ITimeBombCallback*>())
- .def("Go", &TimeBomb::Go)
- .def("Join", &TimeBomb::Join)
- ;
- }
- int main(int argc, char** argv)
- {
- Py_Initialize();
- initkaboom(); // Initializes the Boost.Python module I defined.
- // Load up the auto execution script and then open up the command prompt
- object main_module((handle<>(borrowed(PyImport_AddModule("__main__")))));
- object main_namespace = main_module.attr("__dict__");
- try
- {
- handle<> ignored(( PyRun_String( "execfile('test_script.py')",
- Py_file_input,
- main_namespace.ptr(),
- main_namespace.ptr() ) ));
- }
- catch(...)
- {
- // If an exception was thrown, translate it to Python. Sometimes
- // this even works!
- // When there are problems with the script up front, I just get
- // flung to the Python command line. That's on my list of things
- // to improve...
- boost::python::handle_exception();
- }
- Py_Main(argc, argv);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement