OpenersNotesSection(Spacer1)Details

MLGetFunction() allocates memory for the character string corresponding to the name of the head of the function. You must call (NonWLLink[MLReleaseSymbol(), paclet:ref/c/MLReleaseSymbol]) to disown this memory. If MLGetFunction() fails and the function's return value indicates an error, do not call (NonWLLink[MLReleaseSymbol(), paclet:ref/c/MLReleaseSymbol]) on the contents of s.

External programs should not modify the character string s.

MLGetFunction(link,&s,&n) has the same effect as (NonWLLink[MLGetNext, paclet:ref/c/MLGetNext])(link);(NonWLLink[MLGetArgCount, paclet:ref/c/MLGetArgCount])(link,&n);(NonWLLink[MLGetSymbol, paclet:ref/c/MLGetSymbol])(link,&s).

MLGetFunction() returns 0 in the event of an error, and a nonzero value if the function succeeds.

Use (NonWLLink[MLError(), paclet:ref/c/MLError]) to retrieve the error code if MLGetFunction() fails.

MLGetFunction() is declared in the MathLink header file (RefLink[mathlink.h, paclet:ref/file/mathlink.h]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

#include "mathlink.h"

/* read a Mathematica function from a link */

void f(MLINK lp)
{
	const char *f;
	int n;

	if(! MLGetFunction(lp, &f, &n))
		{
			/* unable to read the function from lp */
			return;
		}

	/* ... */

	MLReleaseSymbol(lp, f);
}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(NonWLLink[MLReleaseSymbol(), paclet:/ref/c/MLReleaseSymbol])  ▪  (NonWLLink[MLGetNext(), paclet:/ref/c/MLGetNext])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Manipulating Expressions in External Programs, paclet:tutorial/ManipulatingExpressionsInExternalPrograms])}, {▪(RefLinkPlain[Handling Lists, Arrays and Other Expressions, paclet:tutorial/HandlingListsArraysAndOtherExpressions])}})}})