Scilab GetVar() Function of Scilab API
This function accepts string name of a Scilab parser variable. Its syntax is
scilabVar scilab_getVar(const wchar_t* name)
It returns variable called ``name". If variable does not exist then it returns NULL. For example
--> myV = 5;
--> myGetVar("myV")
variable is accepted by {scilab_getVar} as its argument. {scilab_getVar} function does not accept variable name directly as string but variable name string is passed through {scilab_getString} function. The correct steps for calling {scilab_getVar} function are given in following code.
.......
int sci_myGetVar(\
scilabEnv env, \
int nin, \
scilabVar* in ,\
int nopt, \
scilabOpt opt, \
int nout, \
scilabVar* out\
){
.......
//Scilab string data type variable
wchar_t* str = 0;
//Copy input "myV" into str variable
scilab_getString(env, in[0], &str);
//Get variable "myV" and return value
//assigned to scilab variable myV
out[0] = scilab_getVar(str);
.......
}
The output of Scilab interface function would be equal to the value of `myV'. The complete codes are given below:
--> cd pathconvert(TMPDIR);
--> mkdir(pathconvert(TMPDIR+'/Build_C/'));
--> cd(pathconvert(TMPDIR+'/Build_C/'));
--> [bOK, ilib] = c_link('libbuild_c');
--> if bOK then
--> ulink(ilib);
--> end
--> ifn=['#include ""api_scilab.h""'
--> '#include ""Scierror.h""'
--> '#include ""localization.h""'
--> '#include ""sciprint.h""'
--> 'const char fname[] = ""myGetVar"";'
--> 'int sci_myGetVar(scilabEnv env, \'
--> ' int nin, scilabVar* in, \'
--> ' int nopt, scilabOpt opt, \'
--> ' int nout, scilabVar* out) '
--> '{'
--> ' wchar_t* str = 0;'
--> ' scilab_getString(env, in[0], &str);'
--> ' out[0] = scilab_getVar(str);'
--> ' return 0;'
--> '}'];
--> //Copy interface as mymyGetVar.c file
--> mputl(ifn,pathconvert(TMPDIR+'/Build_C/mymyGetVar.c',%F));
--> files=['mymyGetVar.c'];
--> //Create the shared library (a gateway, //
--> //a Makefile and a loader are generated. //
--> ilib_build('build_c',["myGetVar","sci_myGetVar","csci6"],files,[]);
--> // load the shared library by executing loader.sce
--> exec loader.sce;
--> //Use the new function
--> v = 5;
--> [a]=myGetVar("v")
a =
5