From: William S F. <ws...@fu...> - 2011-07-12 19:39:02
|
Hi Ernest, I'm not sure this has been given any thought for directors, but, it does seem to work as expected. However, the numinputs needs to be specified with the 'in' typemap. %typemap(directorargout) Task *& pTask { /* directorargout typemap */ } %typemap(in, numinputs=0) Task *& pTask { /* custom in typemap */ } The directorin typemap is ignored (there is no need for it) and the directorargout typemap is generated. The create method then take no arguments in Python. William On 28/06/11 18:43, Ernest Obusek wrote: > Can anyone confirm at least that it should work they way I expect it to here? That would mean swig has a problem. Or has anyone done this successfully (meaning I'm doing something wrong)? I see this with swig 1.3.39 and 2.0.3. > > Thanks, > Ernest > > > On Jun 27, 2011, at 2:21 PM, Ernest Obusek wrote: > >> I'm using swig to wrap python for use in a C++ program, and all uses of python calling into C++ are working well and I seem to understand typemaps for that well enough for now. But I'm having trouble with calls in the other direction. I have a C++ class with this function: >> >> virtual int create(Task*& pTask); >> >> The implementation must create a new Task instance and return it in the passed in pointer. In Python I want this to work like so: >> >> def create(self): >> newTask = TaskSubClassInPython() >> return newTask >> >> To wrap this I've created a pair of typemaps for directorin and directorargout, and I'm having trouble with the directorin typemap. Since I don't want to pass an argument to the python function, I created this directorin typemap: >> >> %typemap(directorin, numinputs=0) Cmd*& OUTPUT >> { >> } >> >> But the generated code wants to pass a wrapped pTask into the Python function: >> >> Result_t SwigDirector_Task::create(Task*& OUTPUT) { >> PyObject *output; >> Result_t c_result; >> swig::SwigVar_PyObject obj0; >> { >> >> } >> if (!swig_get_self()) { >> Swig::DirectorException::raise("'self' uninitialized, maybe you forgot to call Test.__init__."); >> swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *)"create", (char *)"(O)" ,(PyObject *)obj0); >> >> >> I must be doing something wrong here, but I don't see it. Does anything here stand out to anyone else? >> >> Thanks! >> >> - Ernest >> >> >> ------------------------------------------------------------------------------ >> All of the data generated in your IT infrastructure is seriously valuable. >> Why? It contains a definitive record of application performance, security >> threats, fraudulent activity, and more. Splunk takes this data and makes >> sense of it. IT sense. And common sense. >> http://p.sf.net/sfu/splunk-d2d-c2 >> _______________________________________________ >> Swig-user mailing list >> Swi...@li... >> https://lists.sourceforge.net/lists/listinfo/swig-user > > > ------------------------------------------------------------------------------ > All of the data generated in your IT infrastructure is seriously valuable. > Why? It contains a definitive record of application performance, security > threats, fraudulent activity, and more. Splunk takes this data and makes > sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-d2d-c2 > _______________________________________________ > Swig-user mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-user > |