Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2025.0.0 - Français


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.

scilabVar scilab_getClone(scilabEnv env, scilabVar var)

Return a copie of var.

int scilab_getType(scilabEnv env, scilabVar var)

Get type of var.

int scilab_isDouble(scilabEnv env, scilabVar var)
int scilab_isBoolean(scilabEnv env, scilabVar var)
int scilab_isString(scilabEnv env, scilabVar var)
int scilab_isInt(scilabEnv env, scilabVar var)
int scilab_isPoly(scilabEnv env, scilabVar var)
int scilab_isList(scilabEnv env, scilabVar var)
int scilab_isTList(scilabEnv env, scilabVar var)
int scilab_isMList(scilabEnv env, scilabVar var)
int scilab_isHandle(scilabEnv env, scilabVar var)
int scilab_isStruct(scilabEnv env, scilabVar var)
int scilab_isCell(scilabEnv env, scilabVar var)
int scilab_isPointer(scilabEnv env, scilabVar var)

Return 1 if variable var has the right type.

int scilab_isComplex(scilabEnv env, scilabVar var)

Return 1 if variable var is complex.

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_isEmpty(scilabEnv env, scilabVar var)

Return 1 for empty matrix and empty list.

int scilab_isMatrix2d(scilabEnv env, scilabVar var)

Return 1 for matrix with 2 dimensions and scalar.

int scilab_isScalar(scilabEnv env, scilabVar var)

Return 1 for scalar value.

int scilab_isSquare(scilabEnv env, scilabVar var)

Return 1 for matrix with 2 dimensions and dimensions have the same size.

int scilab_isVector(scilabEnv env, scilabVar var)
int scilab_isNVector(scilabEnv env, scilabVar var, int n)
int scilab_isRowVector(scilabEnv env, scilabVar var)
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 >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Oct 24 11:16:04 CEST 2024