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-en.txt
13 #include "ScilabGateway.hxx"
15 namespace org_modules_external_objects
18 int ScilabGateway::array(char * fname, const int envId, void * pvApiCtx)
26 ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId);
30 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong number of arguments : more than %d expected."), 2);
33 OptionsHelper::setCopyOccured(false);
34 ScilabObjects::initialization(env, pvApiCtx);
35 env.getGatewayOptions().setIsNew(false);
37 className = ScilabObjects::getSingleString(1, pvApiCtx);
39 args = new int[Rhs - 1];
41 for (int i = 0; i < Rhs - 1; i++)
43 err = getVarAddressFromPosition(pvApiCtx, i + 2, &addr);
47 freeAllocatedSingleString(className);
48 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
51 args[i] = ScilabObjects::isPositiveIntegerAtAddress(addr, pvApiCtx);
53 if (args[i] == -1 || args[i] == 0)
56 freeAllocatedSingleString(className);
57 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("A strictly positive integer is expected at position %d."), i + 2);
63 ret = env.createarray(className, args, Rhs - 1);
65 catch (std::exception & e)
68 freeAllocatedSingleString(className);
73 freeAllocatedSingleString(className);
77 ScilabObjects::createEnvironmentObjectAtPos(EXTERNAL_OBJECT, Rhs + 1, ret, envId, pvApiCtx);
79 catch (ScilabAbstractEnvironmentException & e)
81 env.removeobject(ret);