How to call function with pointer to a function argument?

Hello,

let’s say we define, e.g., following functions (myfun.C):

#include <iostream>

void myfun(const char * msg){
   std::cout << " msg = " << msg << std::endl;
}

// Is it possible to call this function (callFunc) from python?
void callFunc(void (*msgFun)(const char*), const char* msg){
    cout << " callFunc:" << endl;
    (*msgFun)(msg);
}

void cppCall(){
     // This works from C++
    callFunc(&myfun,"cppCall");
}

and I would like to call the void callFunc(void (msgFun)(const char), const char* msg) function which takes pointer to a function argument (run.py), something like:

import ROOT
ROOT.gROOT.ProcessLine('.L myfun.C+g')
ROOT.myfun("msg")                          # this is ok
ROOT.cppCall()                                 # this works too 
ROOT.callFunc(ROOT.myfun,"msg2")  # this doesn't work...

but this doesn’t work:

 msg = msg
 callFunc:
 msg = cppCall
Traceback (most recent call last):
  File "run.py", line 6, in <module>
    ROOT.callFunc(ROOT.myfun,"msg2") # this doesn't work...
TypeError: void ::callFunc(void (*)(const char*) msgFun, const char* msg) =>
    could not convert argument 1 (void/unknown arguments can't be set)

Is it possible to call the callFunc somehow from python?

Thank you in advance,
Jiri
myfun.C (361 Bytes)
run.py (206 Bytes)

Jiri,

function pointers by argument are currently not supported (is on the TODO list … ). As is, global functions don’t go directly through the function pointer, but through the stub, so I’d have to find a way of peeling of those layers in order to get to the argument.

Cheers,
Wim

Hi,

ohh #-o. Ok, I’ll have to find another way but it is definitely on my WISHLIST :smiley:
Thanks for explenation.

Cheers,
Jiri