1 /*********************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011-2012 OmegaSDG **
5 *********************************/
11 #include <boost/python/errors.hpp>
12 #include <boost/python/import.hpp>
13 #include <boost/python/object.hpp>
14 #include <boost/python/ptr.hpp>
15 #include <boost/python/scope.hpp>
18 #include <boost/python/class.hpp>
19 #include <boost/python/operators.hpp>
20 #include <boost/python/other.hpp>
21 #include <boost/python/self.hpp>
23 //! Initialize Python libraries for use.
26 //! Free resourcers used by Python libraries and uninitialize them.
27 void pythonFinalize();
29 //! Print last error received within Python.
33 //! Access to global namespace shared by all Python scripts.
34 boost::python::object
pythonGlobals();
36 //! Convenience function for binding a C++ object into the global Python
39 void pythonSetGlobal(const char* name
, T pointer
)
42 pythonGlobals()[name
] = boost::python::ptr(pointer
);
43 } catch (boost::python::error_already_set
) {
49 void pythonAddFunction(const char* name
, Fn fn
)
51 using namespace boost::python
;
54 scope
bltins(import("__builtin__"));
56 } catch (error_already_set
) {
62 //! Compile a Python script. Must provide both a representative filename for
63 //! any error messages along with a string containing the body of code to
64 //! compile. Returns NULL on failure and prints any errors.
65 PyCodeObject
* pythonCompile(const char* fn
, const char* code
);
67 //! Run a compiled Python script. Returns false on runtime error and prints the
69 bool pythonExec(PyCodeObject
* code
);