150 Modelica Language Specification 3.1
the error similarly to an assert in the Modelica code.
ModelicaFormatError
void ModelicaFormatError(const char* string, ...)
Output the error message under the same format control as
the C-function
printf. This function never returns to the
calling function, but handles the error similarly to an assert
in the Modelica code.
ModelicaAllocateString
char* ModelicaAllocateString(size_t len)
Allocate memory for a Modelica string which is used as
return argument of an external Modelica function. Note,
that the storage for string arrays (= pointer to string array)
is still provided by the calling program, as for any other
array. If an error occurs, this function does not return, but
calls "
ModelicaError".
ModelicaAllocateStringWithErrorReturn
char* ModelicaAllocateStringWithErrorReturn(size_t len)
Same as
ModelicaAllocateString, except that in case
of error, the function returns 0. This allows the external
function to close files and free other open resources in case
of error. After cleaning up resources use
ModelicaError
or ModelicaFormatError to signal the error.
12.9.7 External Objects
External functions may have internal memory reported between function calls. Within Modelica this memory is
defined as instance of the predefined class ExternalObject according to the following rules:
• There is a predefined partial class
ExternalObject [since the class is partial, it is not possible to define
an instance of this class].
• An external object class shall be directly extended from
ExternalObject, shall have exactly two function
definitions, called "
constructor" and "destructor", and shall not contain other elements.
• The
constructor function is called exactly once before the first use of the object. For each completely
constructed object, the destructor is called exactly once, after the last use of the object, even if an error
occurs. The
constructor shall have exactly one output argument in which the constructed
ExternalObject is returned. The destructor shall have no output arguments and the only input
argument of the destructor shall be the ExternalObject. It is not legal to call explicitly the
constructor and destructor functions.
• Classes derived from
ExternalObject can neither be used in an extends-clause nor in a short class
definition.
• External functions may be defined which operate on the internal memory of an
ExternalObject. An
ExternalObject used as input argument or return value of an external C-function is mapped to the C-type
"void*".
[Example:
A user-defined table may be defined in the following way as an
ExternalObject
(the table is read in a user-defined format from file and has memory for the last used table interval):
class MyTable
extends ExternalObject;
function constructor
input String fileName = "";
input String tableName = "";
output MyTable table;
external "C" table = initMyTable(fileName, tableName);
end constructor;