2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
13 #include "ScilabObjects.hxx"
19 extern int C2F(varfunptr)(int *, int *, int *);
22 namespace org_modules_external_objects
24 bool ScilabObjects::isInit = false;
25 const char * ScilabObjects::_EOBJ[] = {"_EObj", "_EnvId", "_id"};
26 const char * ScilabObjects::_ECLASS[] = {"_EClass", "_EnvId", "_id"};
27 const char * ScilabObjects::_EVOID[] = {"_EVoid", "_EnvId", "_id"};
28 const char * ScilabObjects::_INVOKE_ = "!!_invoke_";
30 void ScilabObjects::initialization(ScilabAbstractEnvironment & env, void * pvApiCtx)
38 int ScilabObjects::createNamedEnvironmentObject(int type, const char * name, int id, const int envId, void * pvApiCtx)
46 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid environment"));
52 fields = static_cast<const char **>(_EOBJ);
55 fields = static_cast<const char **>(_ECLASS);
58 fields = static_cast<const char **>(_EVOID);
61 fields = static_cast<const char **>(_EOBJ);
65 err = createNamedMList(pvApiCtx, name, FIELDS_LENGTH, &mlistaddr);
68 if (err.iErr == API_ERROR_INVALID_NAME)
70 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable name: %s"), name);
73 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot allocate memory"));
76 err = createMatrixOfStringInNamedList(pvApiCtx, name, mlistaddr, 1, 1, FIELDS_LENGTH, fields);
79 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot allocate memory"));
82 err = createMatrixOfInteger32InNamedList(pvApiCtx, name, mlistaddr, EXTERNAL_ENV_ID_POSITION, 1, 1, &envId);
85 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot allocate memory"));
88 err = createMatrixOfInteger32InNamedList(pvApiCtx, name, mlistaddr, EXTERNAL_OBJ_ID_POSITION, 1, 1, &id);
91 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot allocate memory"));
97 void ScilabObjects::createEnvironmentObjectAtPos(int type, int pos, int id, const int envId, void * pvApiCtx)
99 const char ** fields = 0;
105 throw ScilabAbstractEnvironmentException("Invalid environment");
110 case EXTERNAL_OBJECT:
111 fields = static_cast<const char **>(_EOBJ);
114 fields = static_cast<const char **>(_ECLASS);
117 fields = static_cast<const char **>(_EVOID);
120 fields = static_cast<const char **>(_EOBJ);
124 err = createMList(pvApiCtx, pos, FIELDS_LENGTH, &mlistaddr);
127 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot allocate memory"));
130 err = createMatrixOfStringInList(pvApiCtx, pos, mlistaddr, 1, 1, FIELDS_LENGTH, fields);
133 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot allocate memory"));
136 err = createMatrixOfInteger32InList(pvApiCtx, pos, mlistaddr, EXTERNAL_ENV_ID_POSITION, 1, 1, &envId);
139 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot allocate memory"));
142 err = createMatrixOfInteger32InList(pvApiCtx, pos, mlistaddr, EXTERNAL_OBJ_ID_POSITION, 1, 1, &id);
145 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot allocate memory"));
149 void ScilabObjects::copyInvocationMacroToStack(int pos, ScilabAbstractEnvironment & env, void * pvApiCtx)
151 static bool init = false;
153 static int interf = 0;
154 static int funnumber = 0;
159 C2F(str2name)(const_cast<char *>(_INVOKE_), id, strlen(_INVOKE_));
161 int funs = C2F(com).fun;
165 interf = C2F(com).fun;
171 // Remove 1 since varfunptr will increment Top
172 Top = Top - Rhs + pos - 1;
174 // Create a function pointer variable
175 C2F(varfunptr)(id, &interf, &funnumber);
176 C2F(intersci).ntypes[pos - 1] = '$';
180 OptionsHelper::setCopyOccurred(true);
183 void ScilabObjects::removeTemporaryVars(const int envId, int * tmpvar)
185 if (tmpvar && *tmpvar)
187 ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId);
188 env.removeobject(tmpvar + 1, *tmpvar);
193 void ScilabObjects::removeVar(int * addr, void * pvApiCtx)
196 int type, row, col, * id;
198 err = getVarType(pvApiCtx, addr, &type);
201 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
204 if (type == sci_mlist && (isExternalObjOrClass(addr, pvApiCtx)))
206 err = getMatrixOfInteger32InList(pvApiCtx, addr, EXTERNAL_OBJ_ID_POSITION, &row, &col, &id);
209 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
212 int envId = getEnvironmentId(addr, pvApiCtx);
213 ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId);
215 env.removeobject(*id);
217 else if (type == sci_strings)
220 if (getAllocatedSingleString(pvApiCtx, addr, &varName))
222 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
225 err = getVarAddressFromName(pvApiCtx, varName, &addr);
228 freeAllocatedSingleString(varName);
232 err = getVarType(pvApiCtx, addr, &type);
235 freeAllocatedSingleString(varName);
236 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
239 if (type == sci_mlist && isExternalObjOrClass(addr, pvApiCtx))
241 err = getMatrixOfInteger32InList(pvApiCtx, addr, EXTERNAL_OBJ_ID_POSITION, &row, &col, &id);
244 freeAllocatedSingleString(varName);
245 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
248 int envId = getEnvironmentId(addr, pvApiCtx);
249 ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId);
251 env.removeobject(*id);
252 deleteNamedVariable(pvApiCtx, varName);
253 freeAllocatedSingleString(varName);
258 bool ScilabObjects::unwrap(int idObj, int pos, const int envId, void * pvApiCtx)
262 // id == 0 <==> null object plugged on empty matrix
263 if (createEmptyMatrix(pvApiCtx, pos))
265 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot create data"));
270 VariableType type = Nothing;
271 ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId);
272 const ScilabAbstractEnvironmentWrapper & wrapper = env.getWrapper();
274 type = env.isunwrappable(idObj);
280 if (createEmptyMatrix(pvApiCtx, pos))
282 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot create data"));
286 wrapper.unwrapdouble(idObj, ScilabDoubleStackAllocator(pvApiCtx, pos));
289 wrapper.unwraprowdouble(idObj, ScilabDoubleStackAllocator(pvApiCtx, pos));
292 wrapper.unwrapmatdouble(idObj, ScilabDoubleStackAllocator(pvApiCtx, pos));
295 wrapper.unwrapstring(idObj, ScilabStringStackAllocator(pvApiCtx, pos));
298 wrapper.unwraprowstring(idObj, ScilabStringStackAllocator(pvApiCtx, pos));
301 wrapper.unwrapmatstring(idObj, ScilabStringStackAllocator(pvApiCtx, pos));
304 wrapper.unwrapboolean(idObj, ScilabBooleanStackAllocator(pvApiCtx, pos));
307 wrapper.unwraprowboolean(idObj, ScilabBooleanStackAllocator(pvApiCtx, pos));
310 wrapper.unwrapmatboolean(idObj, ScilabBooleanStackAllocator(pvApiCtx, pos));
313 wrapper.unwrapchar(idObj, ScilabCharStackAllocator(pvApiCtx, pos));
316 wrapper.unwraprowchar(idObj, ScilabCharStackAllocator(pvApiCtx, pos));
319 wrapper.unwrapmatchar(idObj, ScilabCharStackAllocator(pvApiCtx, pos));
322 wrapper.unwrapuchar(idObj, ScilabUCharStackAllocator(pvApiCtx, pos));
325 wrapper.unwraprowuchar(idObj, ScilabUCharStackAllocator(pvApiCtx, pos));
328 wrapper.unwrapmatuchar(idObj, ScilabUCharStackAllocator(pvApiCtx, pos));
331 wrapper.unwrapshort(idObj, ScilabShortStackAllocator(pvApiCtx, pos));
334 wrapper.unwraprowshort(idObj, ScilabShortStackAllocator(pvApiCtx, pos));
337 wrapper.unwrapmatshort(idObj, ScilabShortStackAllocator(pvApiCtx, pos));
340 wrapper.unwrapushort(idObj, ScilabUShortStackAllocator(pvApiCtx, pos));
343 wrapper.unwraprowushort(idObj, ScilabUShortStackAllocator(pvApiCtx, pos));
346 wrapper.unwrapmatushort(idObj, ScilabUShortStackAllocator(pvApiCtx, pos));
349 wrapper.unwrapint(idObj, ScilabIntStackAllocator(pvApiCtx, pos));
352 wrapper.unwraprowint(idObj, ScilabIntStackAllocator(pvApiCtx, pos));
355 wrapper.unwrapmatint(idObj, ScilabIntStackAllocator(pvApiCtx, pos));
358 wrapper.unwrapuint(idObj, ScilabUIntStackAllocator(pvApiCtx, pos));
361 wrapper.unwraprowuint(idObj, ScilabUIntStackAllocator(pvApiCtx, pos));
364 wrapper.unwrapmatuint(idObj, ScilabUIntStackAllocator(pvApiCtx, pos));
367 wrapper.unwraplong(idObj, ScilabLongStackAllocator(pvApiCtx, pos));
370 wrapper.unwraprowlong(idObj, ScilabLongStackAllocator(pvApiCtx, pos));
373 wrapper.unwrapmatlong(idObj, ScilabLongStackAllocator(pvApiCtx, pos));
376 wrapper.unwrapulong(idObj, ScilabULongStackAllocator(pvApiCtx, pos));
379 wrapper.unwraprowulong(idObj, ScilabULongStackAllocator(pvApiCtx, pos));
382 wrapper.unwrapmatulong(idObj, ScilabULongStackAllocator(pvApiCtx, pos));
385 wrapper.unwrapfloat(idObj, ScilabFloatStackAllocator(pvApiCtx, pos));
388 wrapper.unwraprowfloat(idObj, ScilabFloatStackAllocator(pvApiCtx, pos));
391 wrapper.unwrapmatfloat(idObj, ScilabFloatStackAllocator(pvApiCtx, pos));
394 wrapper.unwrapcomplex(idObj, ScilabComplexStackAllocator(pvApiCtx, pos));
397 wrapper.unwraprowcomplex(idObj, ScilabComplexStackAllocator(pvApiCtx, pos));
400 wrapper.unwrapmatcomplex(idObj, ScilabComplexStackAllocator(pvApiCtx, pos));
409 int ScilabObjects::getEnvironmentId(int * addr, void * pvApiCtx)
412 int row = 0, col = 0;
415 err = getMatrixOfInteger32InList(pvApiCtx, addr, EXTERNAL_ENV_ID_POSITION, &row, &col, &envId);
418 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
424 int ScilabObjects::getExternalId(int * addr, void * pvApiCtx)
427 int row = 0, col = 0;
430 err = getMatrixOfInteger32InList(pvApiCtx, addr, EXTERNAL_OBJ_ID_POSITION, &row, &col, &id);
433 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
439 int ScilabObjects::getArgumentId(int * addr, int * tmpvars, const bool isRef, const bool isClass, const int envId, void * pvApiCtx)
442 int typ, row = 0, col = 0, returnId;
443 const ScilabAbstractEnvironmentWrapper & wrapper = ScilabEnvironments::getEnvironment(envId).getWrapper();
445 err = getVarType(pvApiCtx, addr, &typ);
448 removeTemporaryVars(envId, tmpvars);
449 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
452 if (isClass && typ != sci_mlist)
454 removeTemporaryVars(envId, tmpvars);
455 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("External Class expected"));
464 if (isVarComplex(pvApiCtx, addr))
467 err = getComplexMatrixOfDouble(pvApiCtx, addr, &row, &col, &mat, &imag);
470 removeTemporaryVars(envId, tmpvars);
471 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
474 returnId = wrap(row, col, mat, imag, wrapper, isRef);
478 err = getMatrixOfDouble(pvApiCtx, addr, &row, &col, &mat);
481 removeTemporaryVars(envId, tmpvars);
482 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
485 returnId = wrap<double>(row, col, mat, wrapper, isRef);
488 tmpvars[++tmpvars[0]] = returnId;
497 err = getMatrixOfIntegerPrecision(pvApiCtx, addr, &prec);
500 removeTemporaryVars(envId, tmpvars);
501 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
507 err = getMatrixOfInteger8(pvApiCtx, addr, &row, &col, (char**)(&ints));
510 removeTemporaryVars(envId, tmpvars);
511 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
514 returnId = wrap<char>(row, col, static_cast<char *>(ints), wrapper, isRef);
515 tmpvars[++tmpvars[0]] = returnId;
518 err = getMatrixOfUnsignedInteger8(pvApiCtx, addr, &row, &col, (unsigned char**)(&ints));
521 removeTemporaryVars(envId, tmpvars);
522 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
525 returnId = wrap<unsigned char>(row, col, static_cast<unsigned char *>(ints), wrapper, isRef);
526 tmpvars[++tmpvars[0]] = returnId;
529 err = getMatrixOfInteger16(pvApiCtx, addr, &row, &col, (short**)(&ints));
532 removeTemporaryVars(envId, tmpvars);
533 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
536 returnId = wrap<short>(row, col, static_cast<short *>(ints), wrapper, isRef);
537 tmpvars[++tmpvars[0]] = returnId;
540 err = getMatrixOfUnsignedInteger16(pvApiCtx, addr, &row, &col, (unsigned short**)(&ints));
543 removeTemporaryVars(envId, tmpvars);
544 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
547 returnId = wrap<unsigned short>(row, col, static_cast<unsigned short *>(ints), wrapper, isRef);
548 tmpvars[++tmpvars[0]] = returnId;
551 err = getMatrixOfInteger32(pvApiCtx, addr, &row, &col, (int**)(&ints));
554 removeTemporaryVars(envId, tmpvars);
555 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
558 returnId = wrap<int>(row, col, static_cast<int *>(ints), wrapper, isRef);
559 tmpvars[++tmpvars[0]] = returnId;
562 err = getMatrixOfUnsignedInteger32(pvApiCtx, addr, &row, &col, (unsigned int**)(&ints));
565 removeTemporaryVars(envId, tmpvars);
566 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
569 returnId = wrap<unsigned int>(row, col, static_cast<unsigned int *>(ints), wrapper, isRef);
570 tmpvars[++tmpvars[0]] = returnId;
573 #ifdef __SCILAB_INT64__
575 err = getMatrixOfInteger64(pvApiCtx, addr, &row, &col, (long long**)(&ints));
578 removeTemporaryVars(envId, tmpvars);
579 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
582 returnId = wrap<long long>(row, col, static_cast<long long *>(ints), wrapper, isRef);
583 tmpvars[++tmpvars[0]] = returnId;
586 err = getMatrixOfUnsignedInteger64(pvApiCtx, addr, &row, &col, (unsigned long long**)(&ints));
589 removeTemporaryVars(envId, tmpvars);
590 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
593 returnId = wrap<unsigned long long>(row, col, static_cast<unsigned long long *>(ints), wrapper, isRef);
594 tmpvars[++tmpvars[0]] = returnId;
602 if (getAllocatedMatrixOfString(pvApiCtx, addr, &row, &col, &matS))
604 removeTemporaryVars(envId, tmpvars);
605 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
608 returnId = wrap<char *>(row, col, matS, wrapper, isRef);
609 freeAllocatedMatrixOfString(row, col, matS);
610 tmpvars[++tmpvars[0]] = returnId;
618 err = getMatrixOfBoolean(pvApiCtx, addr, &row, &col, &matB);
621 removeTemporaryVars(envId, tmpvars);
622 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
625 returnId = wrapBool(row, col, matB, wrapper, isRef);
626 tmpvars[++tmpvars[0]] = returnId;
633 int type = getMListType(addr, pvApiCtx);
634 int eId = getEnvironmentId(addr, pvApiCtx);
636 if (type == EXTERNAL_INVALID)
638 removeTemporaryVars(envId, tmpvars);
639 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("External object expected"));
642 err = getMatrixOfInteger32InList(pvApiCtx, addr, EXTERNAL_OBJ_ID_POSITION, &row, &col, &id);
645 removeTemporaryVars(envId, tmpvars);
646 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
649 if (eId != envId && id != 0)
651 removeTemporaryVars(envId, tmpvars);
652 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Incompatible External object"));
657 if (type == EXTERNAL_CLASS)
663 removeTemporaryVars(envId, tmpvars);
664 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("External Class expected"));
668 if (type == EXTERNAL_OBJECT || type == EXTERNAL_CLASS)
672 else if (type == EXTERNAL_VOID)
681 removeTemporaryVars(envId, tmpvars);
682 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Unable to wrap. Unmanaged datatype (%d) ?"), typ);
689 int ScilabObjects::getMListType(int * mlist, void * pvApiCtx)
691 char * mlist_type[3];
697 // OK it's crappy... but it works and it is performant...
701 return EXTERNAL_VOID;
704 if (mlist[0] != sci_mlist || mlist[1] != 3)
706 return EXTERNAL_INVALID;
709 if (mlist[6] != sci_strings || mlist[7] != 1 || mlist[8] != 3)
711 // first field is not a matrix 1x3 of strings
712 return EXTERNAL_INVALID;
715 if (mlist[11] - 1 == strlen("_EClass") && mlist[14] == 36 && mlist[15] == -14 && mlist[16] == -12 && mlist[17] == 21 && mlist[18] == 10 && mlist[19] == 28 && mlist[20] == 28)
717 return EXTERNAL_CLASS;
720 if (mlist[11] - 1 == strlen("_EObj") && mlist[14] == 36 && mlist[15] == -14 && mlist[16] == -24 && mlist[17] == 11 && mlist[18] == 19)
722 return EXTERNAL_OBJECT;
725 if (mlist[11] - 1 == strlen("_EVoid") && mlist[14] == 36 && mlist[15] == -14 && mlist[16] == -31 && mlist[17] == 24 && mlist[18] == 18 && mlist[19] == 13)
727 return EXTERNAL_VOID;
730 return EXTERNAL_INVALID;
733 bool ScilabObjects::isValidExternal(int * mlist, void * pvApiCtx)
735 int type = getMListType(mlist, pvApiCtx);
736 return type == EXTERNAL_OBJECT || type == EXTERNAL_CLASS;
739 bool ScilabObjects::isExternalObj(int * mlist, void * pvApiCtx)
741 return getMListType(mlist, pvApiCtx) == EXTERNAL_OBJECT;
744 bool ScilabObjects::isExternalClass(int * mlist, void * pvApiCtx)
746 return getMListType(mlist, pvApiCtx) == EXTERNAL_CLASS;
749 bool ScilabObjects::isExternalObjOrClass(int * mlist, void * pvApiCtx)
751 int type = getMListType(mlist, pvApiCtx);
752 return type == EXTERNAL_OBJECT || type == EXTERNAL_CLASS;
755 bool ScilabObjects::isExternalVoid(int * mlist, void * pvApiCtx)
757 return getMListType(mlist, pvApiCtx) == EXTERNAL_VOID;
760 char * ScilabObjects::getSingleString(int pos, void * pvApiCtx)
766 err = getVarAddressFromPosition(pvApiCtx, pos, &addr);
769 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid String"));
772 if (!isStringType(pvApiCtx, addr))
774 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("A single string expected"));
777 if (!isScalar(pvApiCtx, addr))
779 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("A single String expected"));
782 if (getAllocatedSingleString(pvApiCtx, addr, &str))
784 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid String"));
790 int ScilabObjects::isPositiveIntegerAtAddress(int * addr, void * pvApiCtx)
793 int typ = 0, row, col, prec;
795 err = getVarDimension(pvApiCtx, addr, &row, &col);
801 if (row != 1 || col != 1)
806 err = getVarType(pvApiCtx, addr, &typ);
814 err = getMatrixOfIntegerPrecision(pvApiCtx, addr, &prec);
824 err = getMatrixOfInteger8(pvApiCtx, addr, &row, &col, &cvalue);
829 return (int)(*cvalue);
834 unsigned char * ucvalue = 0;
835 err = getMatrixOfUnsignedInteger8(pvApiCtx, addr, &row, &col, &ucvalue);
840 return (int)(*ucvalue);
846 err = getMatrixOfInteger16(pvApiCtx, addr, &row, &col, &svalue);
851 return (int)(*svalue);
856 unsigned short * usvalue = 0;
857 err = getMatrixOfUnsignedInteger16(pvApiCtx, addr, &row, &col, &usvalue);
862 return (int)(*usvalue);
868 err = getMatrixOfInteger32(pvApiCtx, addr, &row, &col, &ivalue);
873 return (int)(*ivalue);
878 unsigned int * uivalue = 0;
879 err = getMatrixOfUnsignedInteger32(pvApiCtx, addr, &row, &col, &uivalue);
884 return (int)(*uivalue);
887 #ifdef __SCILAB_INT64__
890 long long * llvalue = 0;
891 err = getMatrixOfInteger64(pvApiCtx, addr, &row, &col, &llvalue);
896 return (int)(*llvalue);
901 unsigned long long * ullvalue = 0;
902 err = getMatrixOfUnsignedInteger64(pvApiCtx, addr, &row, &col, &ullvalue);
907 return (int)(*ullvalue);
915 else if (typ == sci_matrix)
919 if (isVarComplex(pvApiCtx, addr))
924 err = getMatrixOfDouble(pvApiCtx, addr, &row, &col, &dvalue);
930 if (*dvalue - (double)(int)(*dvalue) == 0.0)
932 return (int)(*dvalue);