Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2023.0.0 - English


API list-type functions

This page lists all the functions to manipulate Scilab native lists.

scilabVar scilab_createList( scilabEnv env)

Create a list.

scilabVar scilab_createTList( scilabEnv env)

Create a tlist.

scilabVar scilab_createMList( scilabEnv env)

Create a mlist.

scilabVar scilab_getListItem( scilabEnv env, scilabVar var, int index)

Get item at position index from list-type variable var.

scilabStatus scilab_setListItem( scilabEnv env, scilabVar var, int index, scilabVar val)

set item val at position index in list-type variable var.

int scilab_getTListFieldNames( scilabEnv env, scilabVar var, wchar_t*** fieldnames)

Get fields names of tlist variable var and return size.

scilabVar scilab_getTListField( scilabEnv env, scilabVar var, const wchar_t* field)

Get field value of tlist variable var.

scilabStatus scilab_setTListField( scilabEnv env, scilabVar var, const wchar_t* field, scilabVar val)

Set field value of tlist variable var.

int scilab_getMListFieldNames( scilabEnv env, scilabVar var, wchar_t*** fieldnames)

Get fields names of mlist variable var and return size.

scilabVar scilab_getMListField( scilabEnv env, scilabVar var, const wchar_t* field)

Get field value of mlist variable var.

scilabStatus scilab_setMListField( scilabEnv env, scilabVar var, const wchar_t* field, scilabVar val)

Set field value of mlist variable var.

scilabStatus scilab_appendToList( scilabEnv env, scilabVar var, scilabVar val)

Add val at the end of list-type var.

int scilab_isDefined( scilabEnv env, scilabVar var, int index)

Return 1 is item at position index is defined.

int scilab_isUndefined( scilabEnv env, scilabVar var, int index)

Return 1 is item at position index is undefined.

Examples

#include "api_scilab.h"
#include "Scierror.h"
#include "localization.h"
#include "sciprint.h"
#include "sci_malloc.h"

const char fname[] = "list_test";

int sci_list_test(scilabEnv env, int nin, scilabVar* in, int nopt, scilabOpt opt, int nout, scilabVar* out)
{
    int i = 0;
    //input
    scilabVar in1 = NULL;
    int size1 = 0;
    wchar_t** fields = NULL;
    scilabVar in2 = NULL;
    int size2 = 0;
    //output
    scilabVar out1 = NULL;

    //goal is to take string vector and list from intput to
    //create a tlist of type "mylist" with fields names from string and
    //fields data from list.

    if (nin != 2)
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), fname, 2);
        return STATUS_ERROR;
    }

    if (nout != 1)
    {
        Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), fname, 1);
        return STATUS_ERROR;
    }

    //in1
    in1 = in[0];
    if (scilab_isString(env, in1) == 0 || scilab_isVector(env, in1) == 0)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A string vector expected.\n"), fname, 1);
        return STATUS_ERROR;
    }

    size1 = scilab_getSize(env, in1);
    scilab_getStringArray(env, in1, &fields);

    //in2
    in2 = in[1];
    if (scilab_isList(env, in2) == 0)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A list expected.\n"), fname, 2);
        return STATUS_ERROR;
    }

    size2 = scilab_getSize(env, in2);

    if (size1 != size2)
    {
        Scierror(999, _("%s: Arguments #%d and #%d: Same sizes expected.\n"), fname, 1, 2);
        return STATUS_ERROR;
    }

    out1 = scilab_createTList(env, L"mytlist");

    for (i = 0; i < size1; ++i)
    {
        scilab_setTListField(env, out1, fields[i], scilab_getListItem(env, in2, i));
    }

    out[0] = out1;
    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/list_test.c",pathconvert(TMPDIR+"/api_c/list_test.c",%F));

ilib_build("liblist",["list_test","sci_list_test", "csci6"],"list_test.c",[],"","","");
exec("loader.sce");

fields = ["double","string","boolean","poly","list","cell"];
data = list(1, "2", %t, %s, list(1,2,3), {1,2;3,4});
t = list_test(fields, data);

assert_checkequal(typeof(t), "mytlist");
assert_checkequal(t.double, 1);
assert_checkequal(t.string, "2");
assert_checkequal(t.boolean, %t);
assert_checkequal(t.poly, %s);
assert_checkequal(t.list, list(1,2,3));
assert_checkequal(t.cell, {1,2;3,4});
Report an issue
<< API integer functions API Scilab API polynomial 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:
Mon Mar 27 11:52:51 GMT 2023