esch
September 17, 2024, 3:00pm
1
Hello,
The help chapter “Getting started with API_Scilab” gives us an example based on the api_scilab.h header file.
I saw that there exist in the folder Scilab\contrib\toolbox_skeleton\sci_gateway\cpp another API for C++. Is this API official and will it be maintained in the futur ?
Hello, welcome there !
esch:
Is this API official
What I can say is that it is the de facto standard, as all older gateways APIs are wrappers on this new C++ API. In all my contributions (in Scilab itself, or in toolboxes, such as sci_ipopt), I have exclusively used this API. Maybe someone else (@vincent.couvert ) can say why we don’t promote it ?
S.
esch
September 17, 2024, 4:12pm
3
Hello mottelet,
You convinced me to use this C++ API in the futur.
Thank you for your answer and for all the work you do for the community !
ES
Here is an example:
code=[
"#define __STDCPP_WANT_MATH_SPEC_FUNCS__ 1 "
"#include <cmath> "
"#include ""double.hxx"" "
"#include ""function.hxx"" "
"extern ""C"" "
"{ "
"#include ""Scierror.h"" "
"#include ""localization.h"" "
"} "
"/* ==================================================================== */ "
"types::Function::ReturnValue sci_zeta(types::typed_list &in, int _iRetCount, types::typed_list &out) "
"{ "
" types::Double* pDblOut; "
" types::Double* pDblIn; "
" if (in.size() != 1) "
" { "
" Scierror(77, _(""%s: Wrong number of input argument(s): %d expected.\n""), ""zeta"", 1); "
" return types::Function::Error; "
" } "
" if (_iRetCount > 1) "
" { "
" Scierror(78, _(""%s: Wrong number of output argument(s): %d expected.""), ""zeta"", 1); "
" return types::Function::Error; "
" } "
" if (in[0]->isDouble() == false || in[0]->getAs<types::Double>()->isComplex()) "
" { "
" Scierror(999, _(""%s: Wrong type for input argument #%d: real expected.\n""), ""zeta"", 1); "
" return types::Function::Error; "
" } "
" pDblIn = in[0]->getAs<types::Double>(); "
" pDblOut = pDblIn->clone(); "
" for (int i = 0 ; i < pDblIn->getSize() ; ++i) "
" { "
" pDblOut->set(i,std::riemann_zeta(pDblIn->get(i))); "
" } "
" out.push_back(pDblOut); "
" return types::Function::OK; "
"} "
];
ulink
files = fullfile(TMPDIR,"sci_zeta.cpp");
mputl(code,files)
ilib_verbose(2)
ilib_build("zeta", ["zeta" "sci_zeta" "cppsci"],files,[])
exec loader.sce
tic
disp(zeta(0.5))
disp(toc())