Mercurial > octave-nkf
annotate examples/code/myprop.c @ 20297:5c42ff6f0eb1 stable
Clean up MEX example code.
* myfeval.c: Use mxIsChar rather than deprecated mxIsString.
* mypow2.c: Validate that input is a double matrix.
* myprop.c: Use space after '!' operator to conform to Octave conventions.
* myset.c: Use mexPutVariable instead of missing mxSetName and deprecated
mexPutArray. Find existing variable EITHER in global workspace OR in
caller workspace. Don't check both.
* mystruct.c: Clarify input validation message.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 15 Jun 2015 10:24:13 -0700 |
parents | c8240a60dd01 |
children |
rev | line source |
---|---|
6595 | 1 #include "mex.h" |
2 | |
3 void | |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
14855
diff
changeset
|
4 mexFunction (int nlhs, mxArray* plhs[], |
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
14855
diff
changeset
|
5 int nrhs, const mxArray* prhs[]) |
6595 | 6 { |
7 double handle; | |
8 char property[256]; | |
9 | |
10 if (nrhs < 2 || nrhs > 3) | |
11 mexErrMsgTxt ("incorrect number of arguments"); | |
20297 | 12 if (! mxIsDouble (prhs[0])) |
13 mexErrMsgTxt ("handle must be a double scalar"); | |
14 if (! mxIsChar (prhs[1])) | |
15 mexErrMsgTxt ("property must be a string"); | |
17791
224e76250443
Use GNU style coding conventions for code in examples/
Rik <rik@octave.org>
parents:
16867
diff
changeset
|
16 |
6595 | 17 handle = mxGetScalar (prhs[0]); |
18 mxGetString (prhs[1], property, 256); | |
19 plhs[0] = mxDuplicateArray (mexGet (handle, property)); | |
17791
224e76250443
Use GNU style coding conventions for code in examples/
Rik <rik@octave.org>
parents:
16867
diff
changeset
|
20 |
6595 | 21 if (nrhs == 3) |
22 if (mexSet (handle, property, mxDuplicateArray (prhs[2]))) | |
23 mexErrMsgTxt ("failed to set property"); | |
24 } |