2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2012 - 2013 - 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, 1, 2);
29 CheckOutputArgument(pvApiCtx, 0, 1);
31 ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId);
32 ScilabGatewayOptions & options = env.getGatewayOptions();
33 OptionsHelper::setCopyOccurred(false);
34 ScilabObjects::initialization(env, pvApiCtx);
35 options.setIsNew(false);
39 className = strdup("");
43 className = ScilabObjects::getSingleString(1, pvApiCtx);
46 err = getVarAddressFromPosition(pvApiCtx, Rhs, &addr);
49 freeAllocatedSingleString(className);
50 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
53 err = getVarType(pvApiCtx, addr, &iType);
56 freeAllocatedSingleString(className);
57 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
60 if (iType != sci_strings)
62 freeAllocatedSingleString(className);
63 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: A String expected."), 2);
66 err = getVarDimension(pvApiCtx, addr, &row, &col);
69 freeAllocatedSingleString(className);
70 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
73 if ((row < 1 || col != 1) && (col < 1 || row != 1))
75 freeAllocatedSingleString(className);
76 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid dimension for argument #%d: A row or a column expected."), 2);
79 if (getAllocatedMatrixOfString(pvApiCtx, addr, &row, &col, &code))
81 freeAllocatedSingleString(className);
82 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
87 ret = env.compilecode(className, code, row != 1 ? row : col);
89 catch (std::exception & e)
91 freeAllocatedSingleString(className);
92 freeAllocatedMatrixOfString(row, col, code);
96 freeAllocatedSingleString(className);
97 freeAllocatedMatrixOfString(row, col, code);
107 ScilabObjects::createEnvironmentObjectAtPos(EXTERNAL_CLASS, Rhs + 1, ret, envId, pvApiCtx);
109 catch (ScilabAbstractEnvironmentException & e)
111 env.removeobject(ret);