• Main Page
  • Related Pages
  • Classes
  • Files
  • File List
  • File Members

python_class.h

Go to the documentation of this file.
00001 /*
00002    $Id: python_class.h,v 1.10 2005/04/16 17:56:32 ksterker Exp $
00003 
00004    Copyright (C) 2001 Kai Sterker <kaisterker@linuxgames.com>
00005    Part of the Adonthell Project http://adonthell.linuxgames.com
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 
00016 /**
00017  * @file   python_class.h
00018  * @author Kai Sterker <kaisterker@linuxgames.com>
00019  * 
00020  * @brief  Defines the python class. This file is named this way
00021  *         so it doesn't conflicts with Python.h Python's include
00022  *         file on non-case aware systems.
00023  * 
00024  * 
00025  */
00026  
00027 
00028 #ifndef PYTHON_CLASS_H__
00029 #define PYTHON_CLASS_H__
00030 
00031 #include "Python.h"
00032 #include "compile.h"
00033 #include "eval.h"
00034 #include "node.h"
00035 #include "fileops.h"
00036 
00037 /**
00038  * Grant simplified access to the Python interpreter.
00039  * 
00040  */ 
00041 class python
00042 {  
00043 public:
00044     /** 
00045      * Initialise Python and insert the Adonthell include paths.
00046      * 
00047      * 
00048      * @return true in case of success, false otherwise.
00049      */
00050     static void init ();
00051 
00052     /**
00053      * Cleanup Python.
00054      * 
00055      */ 
00056     static void cleanup (); 
00057 
00058     /** 
00059      * Adds a directory to Python's include path.
00060      * 
00061      * @param name directory to add to Python's include path.
00062      */
00063     static void insert_path( char * name);
00064     
00065     /** 
00066      * Execute Python statements contained in a string.
00067      * 
00068      * @param s string containing Python statements to execute.
00069      */
00070     static void exec_string(char * s);
00071     
00072     /** 
00073      * Executes a Python script.
00074      * 
00075      * @param filename name of the file to execute.
00076      * 
00077      * @return true in case of success, false otherwise.
00078      */ 
00079     static bool exec_file (string filename);
00080     
00081     /** 
00082      * Imports a Python module.
00083      * 
00084      * @param filename file name of the module to import.
00085      * 
00086      * @return pointer to the imported module.
00087      */
00088     static PyObject *import_module (string filename);
00089     
00090     /** 
00091      * Dumps any error information to stderr.
00092      * 
00093      */
00094     static void show_traceback( void );
00095     
00096     /** 
00097      * Magic function that makes any C object available to Python!
00098      * 
00099      * @param instance pointer to the instance to pass.
00100      * @param class_name name of the class of the passed instance.
00101      * 
00102      * @return pointer to the passed %object.
00103      */
00104     static PyObject *pass_instance (void* instance, const char* class_name);
00105 
00106     /** 
00107      * Loads a Python tuple previously saved with put_tuple ().
00108      * 
00109      * @param file Opened file where to load the tuple from.
00110      * 
00111      * @return Restored Python tuple.
00112      */
00113     static PyObject * get_tuple (igzstream & file); 
00114 
00115     /** 
00116      * Save a Python tuple into a file.
00117      *
00118      * @warning The Python tuple MUST ONLY be composed of Python strings
00119      * or integers!
00120      * 
00121      * @param tuple Python tuple to save.
00122      * @param file Opened file where to save the tuple to.
00123      */
00124     static void put_tuple (PyObject * tuple, ogzstream & file);  
00125 
00126     static PyObject *module;
00127 };
00128 
00129 #ifndef SWIG
00130 namespace data
00131 {
00132     /**
00133      * Global namespace to use in scripts.
00134      * 
00135      */ 
00136     extern PyObject *globals;
00137 }
00138 #endif
00139 
00140 #endif // PYTHON_CLASS_H__

Generated on Fri Mar 18 2011 for Adonthell by  doxygen 1.7.1