get optional argument (Scilab gateway)
Syntax
int getOptionals(void* _pvCtx, char* fname, rhs_opts opts[])
Arguments
- _pvCtx
Scilab environment pointer, pass in "pvApiCtx" provided by api_scilab.h
- fname
Name of the calling function.
- opts
structure array of optional argument
Description
A C gateway functions which use optional arguments.
Examples
In this example, the C interface function can take several optional arguments and prints theirs dimensions if exists.
#include "api_scilab.h" #include "sciprint.h" #include "sciprint.h" #include "sciprint.h" int sci_use_optional(char * fname) { SciErr sciErr; char* pstName = NULL; int iAge = 0; int iDL = 0; static rhs_opts opts[] = { { -1, "age", -1, 0, 0, NULL}, { -1, "drivinglicense", -1, 0, 0, NULL}, { -1, "name", -1, 0, 0, NULL}, { -1, NULL, -1, 0, 0, NULL} }; int nopt = NumOpt(); CheckInputArgument(pvApiCtx, 0, nopt); CheckOutputArgument(pvApiCtx, 0, 1); if (getOptionals(pvApiCtx, fname, opts) == 0) { //Error return 1; } if (opts[0].iPos != -1) {//age double dblAge = 0; getScalarDouble(pvApiCtx, opts[0].piAddr, &dblAge); iAge = (int)dblAge; } else { iAge = 77; } if (opts[1].iPos != -1) {//drivinglicense getScalarBoolean(pvApiCtx, opts[1].piAddr, &iDL); } else { iDL = 0; } if (opts[2].iPos != -1) {//Name getAllocatedSingleString(pvApiCtx, opts[2].piAddr, &pstName); } else { pstName = strdup("John Doe"); } sciprint("Read information: \n"); sciprint("\tName: \t\t\t%s\n", pstName); sciprint("\tAge: \t\t\t%d\n", iAge); sciprint("\tDriving licence: \t%s\n", iDL ? "Yes" : "No"); //no return value AssignOutputVariable(pvApiCtx, 0) = 1; return 0; }
Scilab test script
use_optional(); use_optional(name = "M. Puffin"); use_optional(age = 25, name = "M. Puffin"); use_optional(drivinglicense = %t, age = 25, name = "M. Puffin");
History
Версия | Описание |
5.5.0 | This function added in Scilab 5.5.0 |
Report an issue | ||
<< optionals | optionals | polynomial >> |