Py: new Exit constructor "newExit"
[Tsunagari.git] / src / python.h
blob82ed1cfdc3d8b482f875dad7b08ade3965b87790
1 /*********************************
2 ** Tsunagari Tile Engine **
3 ** python.h **
4 ** Copyright 2011-2012 OmegaSDG **
5 *********************************/
7 #ifndef PYTHON_H
8 #define PYTHON_H
10 // In this file.
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>
17 // For bindings.
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.
24 bool pythonInit();
26 //! Free resourcers used by Python libraries and uninitialize them.
27 void pythonFinalize();
29 //! Print last error received within Python.
30 void pythonErr();
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
37 //! namespace.
38 template<class T>
39 void pythonSetGlobal(const char* name, T pointer)
41 try {
42 pythonGlobals()[name] = boost::python::ptr(pointer);
43 } catch (boost::python::error_already_set) {
44 pythonErr();
48 template<class Fn>
49 void pythonAddFunction(const char* name, Fn fn)
51 using namespace boost::python;
53 try {
54 scope bltins(import("__builtin__"));
55 def(name, fn);
56 } catch (error_already_set) {
57 pythonErr();
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
68 //! error.
69 bool pythonExec(PyCodeObject* code);
71 #endif