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::wrapAsRef(char * fname, const int envId, void * pvApiCtx)
28 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong number of arguments : more than 1 argument expected."));
31 ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId);
32 ScilabGatewayOptions & options = env.getGatewayOptions();
33 OptionsHelper::setCopyOccured(false);
34 ScilabObjects::initialization(env, pvApiCtx);
35 options.setIsNew(false);
37 CheckOutputArgument(pvApiCtx, Rhs, Rhs);
39 tmpvar = new int[Rhs + 1];
42 for (int i = 1; i < Rhs + 1; i++)
44 err = getVarAddressFromPosition(pvApiCtx, i, &addr);
47 ScilabObjects::removeTemporaryVars(envId, tmpvar);
49 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
52 if (!isScalar(pvApiCtx, addr) || !isStringType(pvApiCtx, addr))
54 ScilabObjects::removeTemporaryVars(envId, tmpvar);
56 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Can only wrap as a reference to a named variable"));
59 if (getAllocatedSingleString(pvApiCtx, addr, &varName))
61 ScilabObjects::removeTemporaryVars(envId, tmpvar);
63 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
66 err = getVarAddressFromName(pvApiCtx, varName, &addr);
67 freeAllocatedSingleString(varName);
70 ScilabObjects::removeTemporaryVars(envId, tmpvar);
72 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
77 idObj = ScilabObjects::getArgumentId(addr, tmpvar, true, false, envId, pvApiCtx);
79 catch (ScilabAbstractEnvironmentException & e)
82 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot wrap argument %d."), i);
87 ScilabObjects::createEnvironmentObjectAtPos(EXTERNAL_OBJECT, Rhs + i, idObj, envId, pvApiCtx);
89 catch (ScilabAbstractEnvironmentException & e)
91 ScilabObjects::removeTemporaryVars(envId, tmpvar);
99 // We don't remove tmpvar since it contains id which are put on rhs