view examples/myset.c @ 14136:20cb178716ee

Make nargin and nargout behave more like Matlab's (Bug #32700) * ov-usr-fcn.cc: Include "ov-fcn-handle.h". (Fnargout, Fnargin) nargout can be given a function handle as well as a string. Allow nargout(fcn) works in the top level. Make inline functions always return 1. Make anonymous functions always return -1. Make functions with varargout optionally preceded by named outputs return -(length_output_list_including_the_varargout).
author Iain Murray <iain@iainmurray.net>
date Mon, 02 Jan 2012 12:49:52 -0500
parents 4295d634797d
children be41c30bcb44
line wrap: on
line source

#include "mex.h"

void
mexFunction (int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
{
  char *str;
  mxArray *v;

  if (nrhs != 2 || ! mxIsString (prhs[0]))
    mexErrMsgTxt ("expects symbol name and value");

  str = mxArrayToString (prhs[0]);

  v = mexGetArray (str, "global");

  if (v)
    {
      mexPrintf ("%s is a global variable with the following value:\n", str);
      mexCallMATLAB (0, 0, 1, &v, "disp");
    }

  v = mexGetArray (str, "caller");

  if (v)
    {
      mexPrintf ("%s is a caller variable with the following value:\n", str);
      mexCallMATLAB (0, 0, 1, &v, "disp");
    }

  // WARNING!! Can't do this in MATLAB!  Must copy variable first.
  mxSetName (prhs[1], str);  
  mexPutArray (prhs[1], "caller");
}