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

Change language to:
Français - 日本語 - Português - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
However, this page did not exist in the previous stable version.

Scilab Help >> API Scilab > handle > handle example

handle example

Handle use case.

Description

This example shows how to get a handle variable and return it to Scilab.

Gateway Source

#include "api_scilab.h"

int handleExample(char *fname,unsigned long fname_len)
{
    SciErr sciErr;
    int* piAddr = NULL;
    int iType   = 0;
    int iRet    = 0;

    CheckInputArgument(pvApiCtx, 1, 1);
    CheckOutputArgument(pvApiCtx, 0, 1);

    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
    if(sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }
    if(isHandleType(pvApiCtx, piAddr))
    {
        if(isScalar(pvApiCtx, piAddr))
        {
            long long llHandle = 0;
            iRet = getScalarHandle(pvApiCtx, piAddr, &llHandle);
            if(iRet)
            {
                return 0;
            }
            iRet = createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, llHandle);
            if(iRet)
            {
                return 0;
            }
        }
        else
        {
            int iRows	= 0;
            int iCols	= 0;
            long long *pllHandle = NULL;

            sciErr = getMatrixOfHandle(pvApiCtx, piAddr, &iRows, &iCols, &pllHandle);
            if(sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 0;
            }

            sciErr = createMatrixOfHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows, iCols, pllHandle);
            if(sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 0;
            }
        }
        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    }
    else
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
    }
    return 0;
}

Scilab test script

a = %t;
b = %f;
c = [a,b;b,a;a,b;b,a];
d = c';

handleExample(a) == a
handleExample(b) == b
handleExample(c) == c
handleExample(d) == d

History

VersionDescription
5.5.0 This function added in Scilab 5.5.0
Report an issue
<< createScalarHandle handle hypermat >>

Copyright (c) 2022-2023 (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 02 13:47:02 CEST 2014