golib
0.5
|
Python embedding. Make sure there exists only one python interpreter. Possibly there can be one per thread, but that is not tested. This is all quite new. More...
Functions | |
bool | init () |
bool | final () |
PyObject * | getMainMod () |
PyObject * | getMainNamespace () |
bool | call (const goString &cmd) |
bool | call (const char *cmd) |
PyObject * | run (const goString &cmd) |
bool | runFile (const char *filename) |
template<class T > | |
bool | convert (PyObject *obj, goVector< T > &ret) |
Convert object to vector. More... | |
PyObject * | getObject (const char *name) |
void | getAllSwigTypes (goList< goString > &ret) |
Get all swig type identifier strings from all swig modules. More... | |
template<class T > | |
void | setSwigPointer (const char *name, T *o, bool own_it, const char *type_str) |
Add a new swig wrapped object to the interpreter. More... | |
template<class T > | |
T * | getSwigPointer (const char *name, bool own_it, const char *type_str) |
Get a swig wrapped object pointer from the python interpreter. More... | |
goFloat | getFloat (const char *name) |
goDouble | getDouble (const char *name) |
void | set (const char *name, goFloat value) |
void | set (const char *name, goDouble value) |
GOPYTHON_GETSET_DECLARATION (goMath::Vectorf, Vectorf) | |
GOPYTHON_GETSET_DECLARATION (goMath::Vectord, Vectord) | |
GOPYTHON_GETSET_DECLARATION (goMath::Matrixf, Matrixf) | |
GOPYTHON_GETSET_DECLARATION (goMath::Matrixd, Matrixd) | |
GOPYTHON_GETSET_DECLARATION (goMath::Matrix< goIndex_t >, Matrixi) | |
GOPYTHON_GETSET_DECLARATION (goSignal3DBase< void >, Signal3DBase) | |
GOPYTHON_GETSET_DECLARATION (goSignal3D< void >, Signal3D) | |
GOPYTHON_GETSET_DECLARATION (goString, String) | |
Variables | |
goMutex | mutex |
PyObject * | mainMod = 0 |
PyObject * | mainNamespace = 0 |
bool | initialised = false |
Python embedding. Make sure there exists only one python interpreter. Possibly there can be one per thread, but that is not tested. This is all quite new.
Programs using this must know the path to the python include file Python.h
when compiling, else compilation will fail.
There are set/get methods for some golib objects, they all look like
set (const char* name, TYPE o, bool own_it);
TYPE getNAME (const char* name, bool own_it);
Examples are goMath::Vectorf* getVectorf (...)
goSignal3D<void>* getSignal3D (...)
All set/get function pairs for swig wrapped objects are created with the macros
GOPYTHON_GETSET_DEFINITION
and GOPYTHON_GETSET_DECLARATION
for definition and declaration, respectively. These macros can also be used to extend this namespace in other libraries / applications. The above macros are just for convenience and create functions the setSwigPointer
/ getSwigPointer
. Functions for simple types should be declared and defined separately.
bool goPython::convert | ( | PyObject * | obj, |
goVector< T > & | ret | ||
) |
Convert object to vector.
Converts a list object with numeric values to a goVector object. Since typechecks are performed and numerical python objects must be converted, this function must be considered slow.
obj | Python list object. |
ret | Target vector. Will be resized. |
Get all swig type identifier strings from all swig modules.
The identifiers can be used e.g. in SWIG_TypeQuery(), so they are the strings you can use in the GOPYTHON_GETSET_DEFINITION macro, for example.
ret | The list of strings. |
T* goPython::getSwigPointer | ( | const char * | name, |
bool | own_it, | ||
const char * | type_str | ||
) |
Get a swig wrapped object pointer from the python interpreter.
All get functions for swig wrapped types are simply using this.
name | Name of the object in python. |
own_it | If true, C++ will own the object. You will then need to deallocate it yourself. |
type_str | Identifier used for SWIG_TypeQuery() |
void goPython::setSwigPointer | ( | const char * | name, |
T * | o, | ||
bool | own_it, | ||
const char * | type_str | ||
) |
Add a new swig wrapped object to the interpreter.
All set functions for swig wrapped types are simply using this.
name | Name of the object in python. |
o | Object to wrap. |
own_it | If true, python will own the object. |
type_str | Identifier used for SWIG_TypeQuery() |