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<std::string> args;
for (unsigned int i = 0; i != len(argv); ++i)
{
extract<char const *> 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<std::string>, 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