How to call function with pointer to a function argument?


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;

void cppCall(){
     // This works from C++

and I would like to call the void callFunc(void (msgFun)(const char), const char* msg) function which takes pointer to a function argument (, 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
 msg = cppCall
Traceback (most recent call last):
  File "", 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,
myfun.C (361 Bytes) (206 Bytes)


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.



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