Custom director overrides

Dima Kogan <[email protected]> Sat, 24 Aug 2024 18:51:30 -0700
Newsgroups gmane.comp.programming.swig
Message-ID <[email protected]>
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.