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::compile(char * fname, const int envId, void * pvApiCtx)
28 CheckInputArgument(pvApiCtx, 2, 2);
30 ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId);
31 ScilabGatewayOptions & options = env.getGatewayOptions();
32 OptionsHelper::setCopyOccurred(false);
33 ScilabObjects::initialization(env, pvApiCtx);
34 options.setIsNew(false);
36 className = ScilabObjects::getSingleString(1, pvApiCtx);
38 err = getVarAddressFromPosition(pvApiCtx, 2, &addr);
41 freeAllocatedSingleString(className);
42 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
45 err = getVarType(pvApiCtx, addr, &iType);
48 freeAllocatedSingleString(className);
49 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
52 if (iType != sci_strings)
54 freeAllocatedSingleString(className);
55 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: A String expected."), 2);
58 err = getVarDimension(pvApiCtx, addr, &row, &col);
61 freeAllocatedSingleString(className);
62 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
65 if ((row < 1 || col != 1) && (col < 1 || row != 1))
67 freeAllocatedSingleString(className);
68 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid dimension for argument #%d: A row or a column expected."), 2);
71 if (getAllocatedMatrixOfString(pvApiCtx, addr, &row, &col, &code))
73 freeAllocatedSingleString(className);
74 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
79 ret = env.compilecode(className, code, row != 1 ? row : col);
81 catch (std::exception & e)
83 freeAllocatedSingleString(className);
84 freeAllocatedMatrixOfString(row, col, code);
88 freeAllocatedSingleString(className);
89 freeAllocatedMatrixOfString(row, col, code);
93 ScilabObjects::createEnvironmentObjectAtPos(EXTERNAL_CLASS, Rhs + 1, ret, envId, pvApiCtx);
95 catch (ScilabAbstractEnvironmentException & e)
97 env.removeobject(ret);