mirror of https://github.com/swig/swig
scilab: support typed constants (U UL L) in scilabconst(1)
This commit is contained in:
parent
6791e3ac7a
commit
20fc167624
|
@ -1,32 +1,35 @@
|
||||||
exec("swigtest.start", -1);
|
exec("swigtest.start", -1);
|
||||||
|
|
||||||
function checkConst(const_val, expected_type, expected_const_val)
|
checkequal(ICONST0_get(), 42, "ICONST0_get()");
|
||||||
if typeof(const_val) <> expected_type then swigtesterror(); end
|
checkequal(FCONST0_get(), 2.1828, "FCONST0_get()");
|
||||||
if const_val <> expected_const_val then swigtesterror(); end
|
checkequal(CCONST0_get(), "x", "CCONST0_get()");
|
||||||
endfunction
|
//checkequal(CCONST0_2_get(), "\n", "CCONST0_2_get()");
|
||||||
|
checkequal(SCONST0_get(), "Hello World", "SCONST0_get()");
|
||||||
|
checkequal(SCONST0_2_get(), """Hello World""", "SCONST0_2_get()");
|
||||||
|
checkequal(EXPR0_get(), 48.5484, "EXPR0_get()");
|
||||||
|
checkequal(iconst0_get(), 37, "iconst0_get()");
|
||||||
|
checkequal(fconst0_get(), 42.2, "fconst0_get()");
|
||||||
|
|
||||||
checkConst(ICONST0_get(), "constant", 42);
|
checkequal(UNSIGNED0_get(), hex2dec("5FFF"), "UNSIGNED0_get()");
|
||||||
checkConst(FCONST0_get(), "constant", 2.1828);
|
checkequal(LONG0_get(), hex2dec("3FFF0000"), "LONG0_get()");
|
||||||
checkConst(CCONST0_get(), "string", "x");
|
checkequal(ULONG0_get(), hex2dec("5FF0000"), "ULONG0_get()");
|
||||||
//checkConst(CCONST0_2_get(), "string", "\n");
|
|
||||||
checkConst(SCONST0_get(), "string", "Hello World");
|
|
||||||
checkConst(SCONST0_2_get(), "string", """Hello World""");
|
|
||||||
checkConst(EXPR0_get(), "constant", 48.5484);
|
|
||||||
checkConst(iconst0_get(), "constant", 37);
|
|
||||||
checkConst(fconst0_get(), "constant", 42.2);
|
|
||||||
|
|
||||||
if isdef('BAR0') then swigtesterror(); end
|
if isdef('BAR0') then swigtesterror("BAR0"); end
|
||||||
|
|
||||||
checkConst(ICONST1, "int32", 42);
|
checkequal(ICONST1, int32(42), "ICONST1");
|
||||||
checkConst(FCONST1, "constant", 2.1828);
|
checkequal(FCONST1, 2.1828, "FCONST1");
|
||||||
checkConst(CCONST1, "string", "x");
|
checkequal(CCONST1, "x", "CCONST1");
|
||||||
//checkConst(CCONST1_2, "string", "\n");
|
//checkequal(CCONST1_2, "\n", "CCONST1_2");
|
||||||
checkConst(SCONST1, "string", "Hello World");
|
checkequal(SCONST1, "Hello World", "SCONST1");
|
||||||
checkConst(SCONST1_2, "string", """Hello World""");
|
checkequal(SCONST1_2, """Hello World""", "SCONST1_2");
|
||||||
checkConst(EXPR1, "constant", 48.5484);
|
checkequal(EXPR1, 48.5484, "EXPR1");
|
||||||
checkConst(iconst0_get(), "constant", 37);
|
checkequal(iconst1, int32(37), "iconst1");
|
||||||
checkConst(fconst0_get(), "constant", 42.2);
|
checkequal(fconst1, 42.2, "fconst1");
|
||||||
|
|
||||||
if isdef('BAR1') then swigtesterror(); end
|
checkequal(UNSIGNED1, uint32(hex2dec("5FFF")), "UNSIGNED1");
|
||||||
|
checkequal(LONG1, int32(hex2dec("3FFF0000")), "LONG1");
|
||||||
|
checkequal(ULONG1, uint32(hex2dec("5FF0000")), "ULONG1");
|
||||||
|
|
||||||
|
if isdef('BAR1') then swigtesterror("BAR1"); end
|
||||||
|
|
||||||
exec("swigtest.quit", -1);
|
exec("swigtest.quit", -1);
|
||||||
|
|
|
@ -10,6 +10,11 @@
|
||||||
#define SCONST0 "Hello World"
|
#define SCONST0 "Hello World"
|
||||||
#define SCONST0_2 "\"Hello World\""
|
#define SCONST0_2 "\"Hello World\""
|
||||||
|
|
||||||
|
/* Constants with type */
|
||||||
|
#define UNSIGNED0 0x5FFFU
|
||||||
|
#define LONG0 0x3FFF0000L
|
||||||
|
#define ULONG0 0x5FF0000UL
|
||||||
|
|
||||||
/* Expressions should work too */
|
/* Expressions should work too */
|
||||||
#define EXPR0 ICONST0 + 3*FCONST0
|
#define EXPR0 ICONST0 + 3*FCONST0
|
||||||
|
|
||||||
|
@ -31,6 +36,11 @@
|
||||||
#define SCONST1 "Hello World"
|
#define SCONST1 "Hello World"
|
||||||
#define SCONST1_2 "\"Hello World\""
|
#define SCONST1_2 "\"Hello World\""
|
||||||
|
|
||||||
|
/* Constants with type */
|
||||||
|
#define UNSIGNED1 0x5FFFU
|
||||||
|
#define LONG1 0x3FFF0000L
|
||||||
|
#define ULONG1 0x5FF0000UL
|
||||||
|
|
||||||
/* Expressions should work too */
|
/* Expressions should work too */
|
||||||
#define EXPR1 ICONST1 + 3*FCONST1
|
#define EXPR1 ICONST1 + 3*FCONST1
|
||||||
|
|
||||||
|
|
|
@ -174,15 +174,33 @@
|
||||||
/* %scilabconstcode() feature typemaps */
|
/* %scilabconstcode() feature typemaps */
|
||||||
/* ---------------------------------------------------------------------------*/
|
/* ---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(double)) double
|
||||||
|
%{
|
||||||
|
if (SWIG_CreateScilabVariable_double(pvApiCtx, "$result", $value) != SWIG_OK)
|
||||||
|
return SWIG_ERROR;
|
||||||
|
%}
|
||||||
|
|
||||||
%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(int)) int
|
%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(int)) int
|
||||||
%{
|
%{
|
||||||
if (SWIG_CreateScilabVariable_int(pvApiCtx, "$result", $value) != SWIG_OK)
|
if (SWIG_CreateScilabVariable_int(pvApiCtx, "$result", $value) != SWIG_OK)
|
||||||
return SWIG_ERROR;
|
return SWIG_ERROR;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(double)) double
|
%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(uint)) unsigned int
|
||||||
%{
|
%{
|
||||||
if (SWIG_CreateScilabVariable_double(pvApiCtx, "$result", $value) != SWIG_OK)
|
if (SWIG_CreateScilabVariable_uint(pvApiCtx, "$result", $value) != SWIG_OK)
|
||||||
|
return SWIG_ERROR;
|
||||||
|
%}
|
||||||
|
|
||||||
|
%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(int)) long
|
||||||
|
%{
|
||||||
|
if (SWIG_CreateScilabVariable_int(pvApiCtx, "$result", $value) != SWIG_OK)
|
||||||
|
return SWIG_ERROR;
|
||||||
|
%}
|
||||||
|
|
||||||
|
%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(uint)) unsigned long
|
||||||
|
%{
|
||||||
|
if (SWIG_CreateScilabVariable_uint(pvApiCtx, "$result", $value) != SWIG_OK)
|
||||||
return SWIG_ERROR;
|
return SWIG_ERROR;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
|
@ -189,3 +189,16 @@ SWIG_SciDouble_FromUnsignedIntArrayAndSize(void *pvApiCtx, int iVarOut, int iRow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_CreateScilabVariable_frag(uint), "wrapper") {
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_CreateScilabVariable_dec(uint)(void *pvApiCtx, const char* psVariableName, const unsigned int uiVariableValue) {
|
||||||
|
SciErr sciErr;
|
||||||
|
sciErr = createNamedMatrixOfUnsignedInteger32(pvApiCtx, psVariableName, 1, 1, &uiVariableValue);
|
||||||
|
if (sciErr.iErr) {
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue