1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
%{
/**
* HAVE_SNPRINTF is defined in several places. This prevents the warning message
* from appearing when compiling the swig interface.
*/
#ifdef HAVE_SNPRINTF
#undef HAVE_SNPRINTF
#endif
/**
* This is a workaround for a minor swig bug when building on gcc 4.6.1 and above.
* Prior to gcc 4.6.1 the STL headers like vector, string, etc. used to
* automatically pull in the cstddef header but starting with gcc 4.6.1 they no
* longer do. This leads to swig generated a file that does not compile so we
* explicitly include cstddef so the swig generated file will compile.
*/
#include <cstddef>
%}
%include "std_string.i"
%include "std_vector.i"
%include "std_pair.i"
%include "std_list.i"
%include "std_map.i"
%include "std_set.i"
%include "typemaps.i"
%include "exception.i"
%module(directors="1") fife
$imports
/**
* Some materials to understand exception handling:
*
* Basics about python exceptions:
* http://docs.python.org/tut/node10.html
* Python exception handling in C APIs
* http://docs.python.org/api/exceptions.html
* http://docs.python.org/api/exceptionHandling.html
* SWIG exception handling
* http://www.swig.org/Doc1.3/Customization.html#exception
* http://www.swig.org/Doc1.3/SWIGPlus.html#SWIGPlus_exception_specifications
* http://www.swig.org/Doc1.3/Python.html#Python_nn36
*/
%feature("autodoc", "1"); // 0 == no param types, 1 == show param types
%{
#include "util/base/fife_stdint.h"
%}
/**
* Integer definitions (See swigs stdint.i implementation)
*
*/
/* Signed. */
typedef signed char int8_t;
typedef short int int16_t;
typedef int int32_t;
#if defined(SWIGWORDSIZE64)
typedef long int int64_t;
#else
typedef long long int int64_t;
#endif
/* Unsigned. */
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
#if defined(SWIGWORDSIZE64)
typedef unsigned long int uint64_t;
#else
typedef unsigned long long int uint64_t;
#endif
namespace std {
%template(StringVector) vector<std::string>;
%template(UintVector) vector<uint32_t>;
%template(IntVector) vector<int32_t>;
%template(FloatVector) vector<float>;
%template(DoubleVector) vector<double>;
%template(BoolVector) vector<bool>;
%template(Uint16Uint16Pair) pair<uint16_t, uint16_t>;
%template(Uint16Uint16PairVector) vector<std::pair<uint16_t, uint16_t> >;
};
%{
#include "util/base/exception.h"
static void handleDirectorException() {
PyObject* exception = NULL;
PyObject* value = NULL;
PyObject* traceback = NULL;
PyErr_Fetch(&exception, &value, &traceback);
PyErr_NormalizeException(&exception, &value, &traceback);
if (exception) {
PySys_SetObject((char*)"last_type", exception);
PySys_SetObject((char*)"last_value", value);
PySys_SetObject((char*)"last_traceback", traceback);
PyObject* d = PyModule_GetDict (PyImport_AddModule ("__main__"));
PyDict_SetItemString(d, "exc_type", exception);
PyDict_SetItemString(d, "exc_value", value);
PyDict_SetItemString(d, "exc_traceback", traceback ? traceback : Py_None);
char buf[1024];
sprintf (buf, "\n\
import traceback\n\
s = 'Traceback (most recent call last):\\n'\n\
for filename, line, function, text in traceback.extract_tb(exc_traceback):\n\
s = s + ' File \"%%s\", line %%d, in %%s\\n %%s' %% (filename, line, function, text)\n\
if s[-1] != '\\n': s = s + '\\n'\n\
for l in traceback.format_exception_only(exc_type, exc_value):\n\
s = s + l\n\
if s[-1] != '\\n': s = s + '\\n'\n\
print(s)\n\
");
PyObject* e = PyRun_String(buf, Py_file_input, d, d);
if (!e) {
PyErr_Print();
}
Py_XDECREF(e);
Py_XDECREF(d);
Py_XDECREF(exception);
Py_XDECREF(value);
Py_XDECREF(traceback);
}
}
#define _FIFE_CONVERTED_EXC_HANDLER(_fife_exc_type, _converted_type) \
catch (FIFE::_fife_exc_type& _e) { \
PyErr_Clear(); \
SWIG_exception(_converted_type, _e.what()); \
}
#define _FIFE_EXC_HANDLER(_fife_exc_type) \
catch (FIFE::_fife_exc_type& _e) { \
SWIG_Python_Raise( \
SWIG_NewPointerObj( \
new FIFE::_fife_exc_type(_e), \
SWIGTYPE_p_FIFE__##_fife_exc_type, SWIG_POINTER_OWN), \
#_fife_exc_type, SWIGTYPE_p_FIFE__##_fife_exc_type); \
SWIG_fail; \
}
#define _FIFE_DIRECTOR_EXC_HANDLER() \
catch (Swig::DirectorException &) { \
PyErr_Clear(); \
SWIG_exception(SWIG_RuntimeError, "Caught a director exception"); \
}
%}
%exceptionclass FIFE::Exception;
%exceptionclass FIFE::SDLException;
%exceptionclass FIFE::NotFound;
%exceptionclass FIFE::NotSet;
%exceptionclass FIFE::IndexOverflow;
%exceptionclass FIFE::InvalidFormat;
%exceptionclass FIFE::CannotOpenFile;
%exceptionclass FIFE::InvalidConversion;
%exceptionclass FIFE::NotSupported;
%exceptionclass FIFE::NameClash;
%exceptionclass FIFE::Duplicate;
%exceptionclass FIFE::ScriptException;
%exceptionclass FIFE::EventException;
%exceptionclass FIFE::GuiException;
%exceptionclass FIFE::InconsistencyDetected;
%exceptionclass FIFE::OutOfMemory;
%extend FIFE::Exception {
const char *__str__() {
return self->what();
}
};
%feature("director:except") {
if ($$error != NULL) {
handleDirectorException();
throw Swig::DirectorMethodException();
}
}
%exception {
try {
$$action
}
_FIFE_DIRECTOR_EXC_HANDLER()
_FIFE_EXC_HANDLER(SDLException)
_FIFE_EXC_HANDLER(NotFound)
_FIFE_EXC_HANDLER(NotSet)
_FIFE_EXC_HANDLER(IndexOverflow)
_FIFE_EXC_HANDLER(InvalidFormat)
_FIFE_EXC_HANDLER(CannotOpenFile)
_FIFE_EXC_HANDLER(InvalidConversion)
_FIFE_EXC_HANDLER(NotSupported)
_FIFE_EXC_HANDLER(NameClash)
_FIFE_EXC_HANDLER(Duplicate)
_FIFE_EXC_HANDLER(ScriptException)
_FIFE_EXC_HANDLER(EventException)
_FIFE_EXC_HANDLER(GuiException)
_FIFE_EXC_HANDLER(InconsistencyDetected)
_FIFE_EXC_HANDLER(OutOfMemory)
_FIFE_EXC_HANDLER(Exception)
}
$inclusions
%include engine/swigwrappers/python/extensions.i.templ
|