API common functions
This page lists all the functions to get information about Scilab native objects.
scilabVar
scilab_getVar
(const wchar_t* name)
Return variable called name
, NULL if variable does not exist.
void scilab_setVar
(const wchar_t* name, scilabVar
var)
Create a new variable called name
.
int scilab_getDim
(scilabEnv
env, scilabVar
var)
Return the number of dimension of var
. Note that scalar variables are 2d matrix of dimension (1, 1)
int scilab_getDim2d
(scilabEnv
env, scilabVar
var, int* row, int* col)
Return dimensions of a 2d variable var
in row
and col
.
int scilab_getDimArray
(scilabEnv
env, scilabVar
var, const int** dims)
Return pointer on array of dimensions of a variable var
in dims
.
int scilab_getSize
(scilabEnv
env, scilabVar
var)
Return size of variable var
.
For matrix type is the result of product of dimension and for others like list is the item count.
int scilab_isMatrix2d
(scilabEnv
env, scilabVar
var)
Return 1 for matrix with 2 dimensions and scalar.
int scilab_isSquare
(scilabEnv
env, scilabVar
var)
Return 1 for matrix with 2 dimensions and dimensions have the same size.
int scilab_isColVector
(scilabEnv
env, scilabVar
var)
Use to check if variable var
is a vector. n
is the dimension to check, scilab_isRowVector
is equivalente to scilab_isNVector(env, var, 1)
int scilab_isHypermat
(scilabEnv
env, scilabVar
var)
Return 1 for matrix with dimensions count is up to 2.
int scilab_overload
(scilabEnv
env, scilabVar
var, int nin, scilabVar
*in, int nout, scilabVar
*out)
Call an overload function following type of var
.
nin
, in
, nout
, out
must be used like in gateway prototype.
int scilab_call
(scilabEnv
env, const wchar_t* name, int nin, scilabVar
*in, int nout, scilabVar
*out)
Call function name
.
nin
, in
, nout
, out
must be used like in gateway prototype.
Examples
#include "api_scilab.h" #include "Scierror.h" #include "localization.h" const char fname[] = "overload_test"; int sci_overload_test(scilabEnv env, int nin, scilabVar* in, int nopt, scilabOpt opt, int nout, scilabVar* out) { if (nin < 1 || nin > 2) { Scierror(999, _("%s: Wrong number of input arguments: %d to %d expected.\n"), fname, 1, 2); return STATUS_ERROR; } //call overload function if (nin == 1) { return scilab_overload(env, in[0], nin, in, nout, out); } else // call function in[0] with in[1] as argument { wchar_t* name = NULL; if (scilab_isString(env, in[0]) == 0 || scilab_isVector(env, in[0]) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1); return STATUS_ERROR; } scilab_getString(env, in[0], &name); return scilab_call(env, name, nin - 1, in + 1, nout, out); } return STATUS_OK; }
Scilab test script
mkdir(pathconvert(TMPDIR+"/api_c/")); cd(pathconvert(TMPDIR+"/api_c/")); copyfile(SCI+"/modules/api_scilab/tests/unit_tests/api_c/overload_test.c",pathconvert(TMPDIR+"/api_c/overload_test.c",%F)); ilib_build("liboverload",["overload_test","sci_overload_test", "csci6"],"overload_test.c",[],"","",""); exec("loader.sce"); a = rand(10, 10); x = overload_test("cos", a); assert_checkequal(x, cos(a)); function x=%s_overload_test(a) x = cos(a); endfunction x = overload_test(a); assert_checkequal(x, cos(a));
Report an issue | ||
<< API double functions | API Scilab | API string functions >> |