Re: Custom director overrides
Rokas Kupstys via Swig-user <[email protected]> Sun, 25 Aug 2024 09:56:26 +0300
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <[email protected]> |
Hi Dima,
In case of python, output parameters are returned by function itself. If
your f function had a void return type then wrapped function would
return modified string s. If return type was say int, then function
would return a tuple (result_int, output_s). See
https://www.swig.org/Doc4.2/Python.html#Python_nn46
-- Rokas Kupstys
On 2024-08-25 04:51, Dima Kogan wrote:
> Hi.
>
> I'm trying to extend a generated director function for a virtual
> override, and having trouble. Can somebody please help, or suggest a
> different way to do this?
>
> I'm trying to swig-wrap a C++ class to Python. I have this:
>
> class C
> {
> ...
> virtual f(char* s);
> };
>
> f() uses the argument s to provide output: the C++ caller of C::f()
> passes in a buffer, and reads what C::f() wrote there. I want to use
> swig directors to provide a custom Python implemention of f().
>
> But Python strings are immutable, so the normal director implementation
> doesn't work, since it uses a Python string to represent s.
>
> A custom implementation is thus needed to workaround this immutability:
> by using a bytearray instead of str; or maybe having the Python function
> return the new string, and the custom code copying it into s[]. In any
> case, I need some custom code in SwigDirector_C::f(), and I don't know
> how to specify that.
>
> Thanks.
>
>
> _______________________________________________
> Swig-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/swig-user