问题描述
我想拥有一个Scilab函数,该函数能够更改其输入变量,例如在C
中我可以拥有
I want to have a Scilab function which is able to alter its input variables, For example in C
I could have
void double(int* x){
*x *= 2;
return;
}
在Scilab中有intppty
,funptr
,addinter
,istk
,sadr
和stk
似乎是相关的,但是我找不到任何有效的示例. Scilab确实具有pointer
类型(即128
).如果您能帮助我解决这个问题,我将不胜感激.
There are intppty
, funptr
, addinter
, istk
, sadr
and stk
in Scilab which seem to be relevant, however I can't find any working example. Scilab does have a pointer
type (i.e. 128
). I would appreciate if you could help me figure this out.
PS1.我还镜像了这个问题在Reddit上.
P.S.1. I have also mirrored this question here on Reddit.
PS2. Scilab还具有可以连接C
/的intersci
,SWIG
,fort
,external
,call
,API_Scilab
/gateway
. C++
函数或Fortran
子例程.不幸的是,不推荐使用intersci
,而SWIG
似乎仅适用于C++
兼容性有限的Linux.
P.S.2. Scilab also have intersci
, SWIG
, fort
, external
, call
, API_Scilab
/gateway
which can interface C
/C++
functions or Fortran
subroutines. Unfortunately intersci
has been deprecated and SWIG
seems to be only for Linux with limited C++
compatibility.
PS3. scilab具有功能重载,它可以处理deff
定义的功能以及%
,<...>
,_...
语法的组合.
P.S.3. scilab has function overloading which can do stuff with the functions defined by deff
and a combination of %
,<...>
,_...
syntax.
PS4 .API_Scilab
/gateway
的工作方式基本上是使用头文件api_scilab.h
提供的功能来扩展代码,并使用ilib_build
进行编译,然后编写loader*.sce
脚本,然后使用exec
加载它.
P.S.4. The way API_Scilab
/gateway
works, is basically you dvelop the code using functionalities provided bu the header file api_scilab.h
, compile it with ilib_build
, write a loader*.sce
script and then load it with exec
.
P.S.5..应该可以使用
atomsInstall('mingw'); atomsLoad('mingw');
但是,正如我所解释的.
However I am not able to get it to work as I have explained here.
推荐答案
这可以通过使用例如C ++ Scilab 6网关(示例需要计算机上的编译器,对于Linux和OSX用户来说应该不是问题):
This is possible by using, e.g. a C++ Scilab 6 gateway (example needs a compiler on the machine, it should not be a problem for Linux and OSX users):
gw=[
"#include ""double.hxx"""
"#include ""function.hxx"""
"types::Function::ReturnValue sci_incr(types::typed_list &in, int _iRetCount,"
" types::typed_list &out)"
"{"
" if (in.size() != 1 || in[0]->isDouble() == false) {"
" throw ast::InternalError(""Wrong type/number of input argument(s)"");"
" }"
" types::Double *pDbl = in[0]->getAs<types::Double>();"
" double *pdbl = pDbl->get();"
""
" for (int i=0; i < pDbl->getSize(); i++) (*pdbl) += 1.0;"
""
" return types::Function::OK;"
"}"];
cd TMPDIR;
mputl(gw,TMPDIR+"/sci_incr.cpp");
ulink
ilib_build("incr", ["incr" "sci_incr" "cppsci"],"sci_incr.cpp", [])
exec loader.sce
在编译/链接接口后,您可以具有以下行为:
After compilation/link of the interface, you can have the following behavior:
--> x=1
x =
1.
--> incr(x)
--> x
x =
2.
但是,不要将其视为功能,因为Scilab语言并非旨在使用它!
However, don't consider this as a feature, because the Scilab language has not been designed to use it !
这篇关于如何通过引用Scilab函数传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!