defarg.swg 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /* This file defines an internal function for processing default arguments
  2. with proxy classes.
  3. There seems to be no straightforward way to write proxy functions
  4. involving default arguments. For example :
  5. def foo(arg1,arg2,*args):
  6. proxyc.foo(arg1,arg2,args)
  7. This fails because args is now a tuple and SWIG doesn't know what to
  8. do with it.
  9. This file allows a different approach :
  10. def foo(arg1,arg2,*args):
  11. proxyc.__call_defarg(proxyc.foo,(arg1,arg2,)+args)
  12. Basically, we form a new tuple from the object, call this special
  13. __call_defarg method and it passes control to the real wrapper function.
  14. An ugly hack, but it works.
  15. */
  16. SWIGINTERN PyObject *swig_call_defargs(PyObject *self, PyObject *args) {
  17. PyObject *func;
  18. PyObject *parms;
  19. if (!PyArg_ParseTuple(args,"OO",&func,&parms))
  20. return NULL;
  21. if (!PyCallable_Check(func)) {
  22. SWIG_PYTHON_THREAD_BEGIN_BLOCK;
  23. PyErr_SetString(PyExc_TypeError, "__call_defarg : Need a callable object!");
  24. SWIG_PYTHON_THREAD_END_BLOCK;
  25. return NULL;
  26. }
  27. return PyEval_CallObject(func,parms);
  28. }