[C++-sig] Pyste,Py++: equivalent of swig typemaps?
Hello, due to limitations of swig I am currently learning Py++ and Pyste (because it seems currently to be better documented than Py++). Does Pyste or Py++ offer typemaps like swig (http://www.swig.org/Doc1.3/SWIGDocumentation.html#Python_nn53) that allow any sequence of input arguments to be wrapped to other Python arguments (like for example ...,int len,char *s,... to a Python string) in any function where they appear, even surrounded by other arguments? The only remotely similar I found documented is http://www.boost.org/doc/libs/1_37_0/libs/python/pyste/doc/wrappers.html which explains how to write a wrapper between C++ STL and Python containers. But such a wrapper has to be rewritten for each and every function. Is there a simple method that automates the repetitive task like swig typemaps? Thanks Mihail ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Pyste,Py++: equivalent of swig typemaps?
Mihail Konstantinov wrote: Hello, due to limitations of swig I am currently learning Py++ and Pyste (because it seems currently to be better documented than Py++). Does Pyste or Py++ offer typemaps like swig (http://www.swig.org/Doc1.3/SWIGDocumentation.html#Python_nn53) that allow any sequence of input arguments to be wrapped to other Python arguments (like for example ...,int len,char *s,... to a Python string) in any function where they appear, even surrounded by other arguments? I'm not entirely sure I understand the question. boost.python provides to-python and from-python converters that seem to be equivalent to the 'typemap' you are referring to. These converters are generated automatically for C++ types you export to python ( http://www.boost.org/doc/libs/1_37_0/libs/python/doc/tutorial/doc/html/python/exposing.html), so the conversion will happen automatically when you pass such a C++ type to a python function. You may start with reading the boost.python tutorial (http://www.boost.org/doc/libs/1_37_0/libs/python/doc/tutorial/doc/html/index.html), as it explains this as well as many more features of boost.python. Py++ and Pyste are just tools that generate boost.python wrapper code automatically. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] [pygccxml-development] Pyste, Py++: equivalent of swig typemaps?
On Sun, Nov 30, 2008 at 8:58 PM, Mihail Konstantinov <[EMAIL PROTECTED]> wrote: > Hello, > due to limitations of swig I am currently learning Py++ and Pyste (because > it seems currently to be better documented than Py++). Hmm. Did you see http://language-binding.net/pyplusplus/pyplusplus.html page? If so what documentation you think it lacks or what could be improved? > Does Pyste or Py++ offer typemaps like swig > (http://www.swig..org/Doc1.3/SWIGDocumentation.html#Python_nn53) that allow > any sequence of input arguments to be wrapped to other Python arguments > (like for example ,int len,char *s,... to a Python string) in any > function where they appear, even surrounded by other arguments? > > The only remotely similar I found documented is > http://www.boost.org/doc/libs/1_37_0/libs/python/pyste/doc/wrappers.html > which explains how to write a wrapper between C++ STL and Python containers. > But such a wrapper has to be rewritten for each and every function. Is there > a simple method that automates the repetitive task like swig typemaps? I can answer for Py++ only. If I understand right, SWIG typemaps, than you are looking for "Function Transformation" feature: http://language-binding.net/pyplusplus/documentation/functions/transformation/transformation.html If you combine it with "query" functionality ( http://language-binding.net/pygccxml/query_interface.html ) you get what you want. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Pyste,Py++: equivalent of swig typemaps?
Thank you Stefan, the typemaps are required, when C++ functions are wrapped that expect arguments which have no direct corresponding type in python, or when standard types have to be interpreted differently. For example a function void parse_args(int argc, char **argv), which I want to call in python as mymodule.parse_args(["arg1","arg2","arg3"]). The wrapper would have to - count the number of python list items and pass this as argc to the C++ function - allocate and fill a list of char* with the strings from the python list. I need even more complicated conversions that are not provided by boost.python. If it is still unclear, I'll try to give more examples. I know that I'm not expressing things very clear, because I have only a basic knowledge of boost.python. Mihail Von: Stefan Seefeld <[EMAIL PROTECTED]> An: Development of Python/C++ integration Gesendet: Sonntag, den 30. November 2008, 20:29:41 Uhr Betreff: Re: [C++-sig] Pyste,Py++: equivalent of swig typemaps? Mihail Konstantinov wrote: > Hello, > due to limitations of swig I am currently learning Py++ and Pyste (because it > seems currently to be better documented than Py++). > > Does Pyste or Py++ offer typemaps like swig > (http://www.swig.org/Doc1.3/SWIGDocumentation.html#Python_nn53) that allow > any sequence of input arguments to be wrapped to other Python arguments (like > for example ...,int len,char *s, to a Python string) in any function > where they appear, even surrounded by other arguments? I'm not entirely sure I understand the question. boost.python provides to-python and from-python converters that seem to be equivalent to the 'typemap' you are referring to. These converters are generated automatically for C++ types you export to python ( http://www.boost.org/doc/libs/1_37_0/libs/python/doc/tutorial/doc/html/python/exposing.html), so the conversion will happen automatically when you pass such a C++ type to a python function. You may start with reading the boost.python tutorial (http://www.boost.org/doc/libs/1_37_0/libs/python/doc/tutorial/doc/html/index.html), as it explains this as well as many more features of boost.python. Py++ and Pyste are just tools that generate boost.python wrapper code automatically. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Pyste,Py++: equivalent of swig typemaps?
Mihail Konstantinov wrote: Thank you Stefan, the typemaps are required, when C++ functions are wrapped that expect arguments which have no direct corresponding type in python, or when standard types have to be interpreted differently. For example a function void parse_args(int argc, char **argv), which I want to call in python as mymodule.parse_args(["arg1","arg2","arg3"]). The wrapper would have to - count the number of python list items and pass this as argc to the C++ function - allocate and fill a list of char* with the strings from the python list. What about this ? void parse_args(list argv) { std::vector args; for (unsigned int i = 0; i != len(argv); ++i) { extract ex(argv[i]); if (ex.check()) // If this is really a string... args.push_back(ex); // ...copy it into a vector else throw some_error(); } my_function(args); } This does what you seem to want: translates a python list of strings into a std::vector, and passes it down to a function. Obviously, you can (attempt to) extract data of arbitrary types from the python list, as long as converters exist. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Pyste,Py++: equivalent of swig typemaps?
On Sun, Nov 30, 2008 at 10:56 PM, Stefan Seefeld <[EMAIL PROTECTED]> wrote: > Mihail Konstantinov wrote: >> >> Thank you Stefan, >> the typemaps are required, when C++ functions are wrapped that expect >> arguments which have no direct corresponding type in python, or when >> standard types have to be interpreted differently. >> >> For example a function void parse_args(int argc, char **argv), which I >> want to call in python as mymodule.parse_args(["arg1","arg2","arg3"]). The >> wrapper would have to - count the number of python list items and pass this >> as argc to the C++ function >> - allocate and fill a list of char* with the strings from the python list. >> > > What about this ? > > void parse_args(list argv) > { > std::vector args; > for (unsigned int i = 0; i != len(argv); ++i) > { > extract ex(argv[i]); > if (ex.check()) // If this is really a string... > args.push_back(ex); // ...copy it into a vector > else > throw some_error(); > } > my_function(args); > } > > > This does what you seem to want: translates a python list of strings into a > std::vector, and passes it down to a function. > Obviously, you can (attempt to) extract data of arbitrary types from the > python list, as long as converters exist. There are few problems with this approach: * It doesn't scale well. Consider exporting the existing project, which has 50-100 functions, which require different transformation. * Although you have to write different code if you want to export [none virtual | virtual | pure virtual] [free | member] function. If I understand right SWIG feature, it allows you to define something like "call policy" which is invoked before and after function invocation, and it also allows you to define complex mapping between Python and C++ arguments. So you can define it once, and then apply it when needed. I could be wrong, but you cant define such "call policy" using Boost.Python. Code generators definitely help in this situation. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Pyste,Py++: equivalent of swig typemaps?
> If I understand right SWIG feature, it allows you to define something > like "call policy" which is invoked before and after function > invocation, and it also allows you to define complex mapping between > Python and C++ arguments. So you can define it once, and then apply it > when needed. Yes, this is what I tried to say, but couldn' t phrase it. > I could be wrong, but you cant define such "call policy" using > Boost.Python. Code generators definitely help in this situation. I'll spend more time to better understand the Py++ docs. Maybe the function transformations do what I need. Thank you Mihail ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig