User`s guide
5 Controlling Code Generation
5-14
This is the corresponding mlfNF interface function (mlfNFoo) for the foo.m
example described earlier in this chapter. This function calls the
Mfoo function
that appears in
foo.c:
/*
* The function "mlfNFoo" contains the nargout interface
* for the "foo" M-function from file
* "<matlab>\extern\examples\compiler\foo.m" (lines 1-8).
* This interface is only produced if the M-function uses
* the special variable "nargout". The nargout interface
* allows the number of requested outputs to be specified
* via the nargout argument, as opposed to the normal
* interface, which dynamically calculates the number of
* outputs based on the number of non-NULL inputs it
* receives. This function processes any input arguments
* and passes them to the implementation version of the
* function, appearing above.
*/
mxArray * mlfNFoo(int nargout,
mxArray * * b,
mxArray * x,
mxArray * y) {
/* ------------- Input Argument Processing ------------ */
mxArray * a = NULL;
mxArray * b__ = NULL;
mlfEnterNewContext(1, 2, b, x, y);
/* ----------------- Call M-Function ------------------ */
a = Mfoo(&b__, nargout, x, y);
/* ------------- Output Argument Processing ----------- */
mlfRestorePreviousContext(1, 2, b, x, y);
if (b != NULL) {
mclCopyOutputArg(b, b__);
} else {
mxDestroyArray(b__);
}
return mlfReturnValue(a);
}