Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Link to external "C" function with variable arguments

Link to external "C" function with variable arguments

I am trying to call an external "C" function which has variable arguments from OpenModelica, however, the model code generated creates a prototype of the external function based on the actual type annd number of arguments passed to it. Is there anyway to get around this?

I essentially want to call functions in a python script from OpenModelica. Since this is not possible (to the best of my knowledge), I am trying to create a generic C++ interface between OpenModelica and Python (since python can be embedded in C++). The issue is for the interface to be generic, I must be able to accept any type and number of arguments from OpenModelica and accordingly pass them to a specified python script function.

Thanks in advance
-Prasant

Re: Link to external "C" function with variable arguments

There is no way to have a varargs-style function in Modelica. And there may be problems calling C++ functions as well (external C is pure C; no overloaded functions).

Re: Link to external "C" function with variable arguments

Thanks for the info. Would something similar be possible if I try to link with an external Java module?

Re: Link to external "C" function with variable arguments

In Java, varargs is an array of objects. I'm 100% sure our external Java interface does not handle that; the signatures will be wrong.

I have one little suggestion regarding a generic interface though: Passing strings. It's slow, but should work.
PythonInterface.callReal("myPythonFunction(" + PythonInterface.realArrayToString(arg1) + ")")

You need to create one "call" function for every return type you want to have anyway, but you can have varargs.

There are 0 guests and 0 other users also viewing this topic
You are here: