[C++-sig] pyste - integration
Nicodemus
nicodemus at globalite.com.br
Fri Sep 12 00:24:38 CEST 2003
Hi Jason,
Jason.Sibthorpe at aculab.com wrote:
>Hi,
>
>Synopsis :
>
>I want to know how/if I can integrate my code
>with pyste to take advantage of its knowledge of function
>arguments so they don't have to be passed to wrap_out_arg
>below.
>
>Detail :
>
>I have written a noddy code generator that takes
>
>wrap_out_arg("test.h", "foo", "char *I, int *O")
>
>(for any number of input args where 'O' indicates
>that it is an output argument, and the type is simple
>- the type need not be simple but if it aint then the result
>might not compile)
>
>and generates
>
>tuple return_args_wrapper(char * in0)
> {
> int * out0;
> return make_tuple(foo(in0, out0),
> out0);
> }
>
>as a wrapper for
>const char *foo(char *str, int *num)
>{...}
>
>where num is an output argument.
>
>It is based on the example supplied by Nicodemus.
>http://mail.python.org/pipermail/c++-sig/2003-September/005393.html
>
>foo_wrapper = Wrapper('foo_wrapper',
>'''
>tuple foo_wrapper(in_type in)
>{
> out_type2 out2;
> out_type1 out1 = foo(in, out2);
> return make_tuple(out1, out2);
>}
>''')
>foo = Function(...)
>set_wrapper(foo, foo_wrapper)
>
>
>
Ok, seems nice.
>=====
>
>I found that I had to have my code in the .pyste file (I could not
>import my module).
>
Why not? You can configure PYTHONPATH to point to the location of your
files, and import them in the .pyste files.
> When attempting the import I got the following
>error
>
> set_wrapper(Function(self.func, self.header),
>TypeError: __init__() takes at least 5 arguments (3 given)
>
>Which is bizarre.
>
Indeed, but what is self in that code? And there's a "," at the end of
it, were there more parameters?
>If I add None, None I get a bit further.
>
> Wrapper(wrapper_name, code))
>NameError: global name 'Wrapper' is not defined
>
Sorry, I don't see any None in this code... could you post a
reproductive test case? This would help a lot to understand your problem. 8)
>even though I explicitly import exporterutils
>from exporterutils import *
>
>Changing the name from Wrapper to FunctionWrapper results in
> File
>"/home/jason/src/boost_cvs/boost/libs/python/pyste/src/Pyste/infos.py", line
>212, in set_wrap
>per
> info._Attribute('wrapper', wrapper)
>AttributeError: 'Function' object has no attribute '_Attribute'
>
>At this point I give up. I suppose my question is, is this related to
>the execfile(interface, context) call in ExecuteInterface? I assume it
>is something to do with the context in which my module is imported, mmm...
>I don't know enough python.
>
Where do you run this code? In the .pyste file or in your own files?
>I would like to integrate this code with pyste to take advantage
>of its knowledge of the declaration so users of wrap_out_arg
>need only specify the out args. Is this possible?
>
Sure! Lots of people have contributed with code and ideas: you're
welcome too. This feature doesn't seem hard to integrate at all. If you
want, mail me off-list so that I guide you in the code.
Thanks for the feedback!
Nicodemus.
More information about the Cplusplus-sig
mailing list