0

I have been using SWIG to make a C library accessible from other languages. The problem I have encountered, is that I need the programmer in the ported languages to be able to override a function which will then be called by some of the functions in the native c code.

So user overrides method in X Language, and the native c code calls this function. What is the best way to go about doing this?

In particular I am looking to be able to do this for scheme.

Flexo
  • 87,323
  • 22
  • 191
  • 272
James
  • 91
  • 8
  • Largely depends on what language X actually is and what the function to be overridden in C looks like. You've said scheme for X, can you elaborate on the C side? (Assuming you really are using C and not C++ I'd guess it's a function pointer?) – Flexo Jul 28 '16 at 08:06
  • It is C and it is a function that needs to get called at a certain point in a loop. The function will be defined by the programmer in the higher level language, it doesn't need to return anything. It is just to hand off control really. – James Jul 28 '16 at 19:53
  • This can be done using a combination of SWIG and ctypes's.`CFUNCTYPE`. An example of this can be found in http://stackoverflow.com/questions/34445045/passing-python-functions-to-swig-wrapped-c-code – Jens Munk Jul 30 '16 at 11:11

0 Answers0