[Scilab-Dev] quetion
sploving
sploving1 at 163.com
Fri May 29 05:30:01 CEST 2009
Hello,
Thank you first. The example helped me a lot. I still have some
questions:
1.As there exists "istk" and "MATRIX_OF_INTEGER_DATATYPE", why do we
wrap the integer such as "int ivar" using "stk" and
"MATRIX_OF_DOUBLE_DATATYPE"? (In fact, I tried to wrap "int ivar" using
istk and "MATRIX_OF_INTEGER_DATATYPE",but failed)
2.Besides "stk,istk,cstk", there is also a "sstk" which is used for
"float" , but I could not find a type such as "MATRIX_OF_FLOAT_DATATYPE"
defined in the "stackTypeVariable.h".So I do not know how to use it.
3.In the "stack-c.h", there are a lot useful API. I only understand a
few of them util now, such as "GetType,GetRhsVar,CreateVar,LhsVar,Rhs",
May I need know all of the rest of them if I want to support the scilab
language in swig? If so, are there any docs or examples that could help
me understand them?
4.I want to write a test-suit file that could test the wrapper file.But
I could not find a similiar file in the docs? Could you give me a simple
file like that? As in octave, it may like this:(rumme.m)
#!/usr/local/bin/octave
example
example.cvar.ivar = 42;
example.cvar.svar = -31000;
printf("ivar = %i\n", example.cvar.ivar);
printf("svar = %i\n", example.cvar.svar);
Thank you for any reply.
Baozeng
在 2009-05-26二的 09:14 +0200,Allan CORNET写道:
> Hi,
>
> A example with string and double variables
>
> if haveacompiler() then
>
> chdir(TMPDIR);
> src = ['#include <stdio.h>'
> '#include ""stack-c.h""'
> '#include ""sciprint.h""'
> '#include ""Scierror.h""'
> ''
> 'static char *cvar = NULL;'
> 'static int ivar = 0;'
> 'int sci_cvar_set (char *fname)'
> '{'
> ' char *arg = NULL;'
> ' int m1 = 0 ;'
> ' int n1 = 0 ;'
> ' int l1 = 0 ;'
>
> ' if (GetType(1) == sci_strings)'
> ' {'
> ' GetRhsVar(1,STRING_DATATYPE ,&m1,&n1,&l1);'
> ' cvar = strdup(cstk(l1));'
> ' }'
> ' else if (GetType(1) == sci_matrix)'
> ' {'
> ' GetRhsVar(1,MATRIX_OF_DOUBLE_DATATYPE ,&m1,&n1,&l1);'
> ' ivar = (int)*stk(l1);'
> ' }'
> ' else'
> ' {'
> ' Scierror(999,""error ...\n"");'
> ' }'
> ''
> ' return 0;'
> '} '
> ''
> 'int sci_cvar_get (char *fname)'
> '{'
> ''
> ' if (GetType(1) == sci_strings)'
> ' {'
> ' int m1 = 0, n1 = 0, l1 = 0;'
> ' int m = 1, n = 0, l = 0;'
> ''
> ' GetRhsVar(1,STRING_DATATYPE ,&m1,&n1,&l1);'
> ' if (strcmp(cstk(l1),""string"") == 0)'
> ' {'
> ' m = 1;'
> ''
> ' if (cvar) n = (int)strlen(cvar);'
> ' else n = (int)strlen("""");'
> ''
> ' CreateVar(Rhs+1,STRING_DATATYPE ,&m,&n,&l); '
> ' if (cvar) strcpy(cstk(l),cvar);'
> ' else strcpy(cstk(l),"""");'
> ' }'
> ' else'
> ' if (strcmp(cstk(l1),""number"") == 0)'
> ' {'
> ' m = 1;'
> ' n = 1;'
> ' CreateVar(Rhs+1,MATRIX_OF_DOUBLE_DATATYPE ,&m,&n,&l); '
> ' *stk(l) = (double)ivar;'
> ' }'
> ' else'
> ' {'
> ' Scierror(999,""error ...\n"");'
> ' return 0;'
> ' }'
> ' LhsVar(1) = Rhs+1;'
> ' }'
> ' else'
> ' {'
> ' Scierror(999,""error ...\n"");'
> ' }'
> ' return 0;'
> '}'
> ];
> mputl(src,'example_cvar.c');
> files=['example_cvar.c'];
> ilib_build('addinter',['cvar_get','sci_cvar_get';'cvar_set','sci_cvar_set'],
> files,[]);
> exec loader.sce;
> cvar_set(33)
> cvar_set('my string')
> cvar_get('string')
> cvar_get('number')
> end
>
> Allan
>
>
> -----Message d'origine-----
> De : sploving [mailto:sploving1 at 163.com]
> Envoyé : mardi 26 mai 2009 06:41
> À : dev at lists.scilab.org
> Objet : [Scilab-Dev] quetion
>
> hi all,
>
> I want to wrap a C variable for scialb. and my wrapper is as follows:
>
> extern char cvar;
>
> int _wrap_cvar_set (char *fname){
> char arg1 ;
> int m1 ;
> int n1 ;
> int l1 ;
>
> {
> GetRhsVar(1,STRING_DATATYPEE ,&m1,&n1,&l1);
> arg1=(char)(*stk(l1));
> }
> cvar = arg1;
>
> return 0;
> }
>
>
> int _wrap_cvar_get (char *fname){
> char result;
> int m ;
> int n ;
> int l ;
>
> result = (char)cvar;
> {
> m=1,n=1;
> CreateVar(Rhs+1,STRING_DATATYPE ,&m,&n,&l);
> *stk(l)=result;
> LhsVar(1)=Rhs+1;
> }
> return 0;
> }
>
> It could not work. Then I use the "MATRIX_OF_STRING_DATATYPE" , it does
> not work either. At last I use the "MATRIX_OF_DOUBLE_DATATYPE", it
> works. But it could not set a char to cvar, as follows:
>
> -->cvar_set(3)
>
> -->cvar_get()
> ans =
>
> 3.
>
> -->cvar_set("b")
> !--error 246
>
> What is the matter? Thanks for any reply.
>
>
> Baozeng
>
>
>
>
>
>
>
>
More information about the dev
mailing list