User docs for mexlib
Mexlib is a module in Scilab YaSp. You can find build instructions in YaSp page.
This module is based in MATLAB mexlib specification.
How to
First of all, to use a mex function you need a mex file. Here is a small example (call it example.c):
#include "mex.h" void mexFunction(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]) { double *output; double data[] = {1.0, 2.1, 3.0}; plhs[0] = mxCreateDoubleMatrix(1, 3, mxREAL); output = mxGetPr(plhs[0]); memcpy(output, data, 3*sizeof(double)); }
This function is really simple, it just return a double array with 3 values. The important part is the mex.h included and mexFunction defined with these arguments.
To compile this file, you should use Scilab ilib_mex_build function (it is not from YaSp docs).
--> ilib_mex_build('libmexexample',['mexgetdouble','example', 'cmex'], 'example.c',[],'Makelib','','','');
This creates a loader file you should run:
--> exec('loader.sce');
After that, just call your function, created with name mexgetdouble:
--> r = mexgetdouble() r = 1 2.1 3