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"
16 * The function !!_invoke_l is called by !_invoke_ which is called on object.method
19 namespace org_modules_external_objects
22 int ScilabGateway::doubleExclam_invoke(char * fname, const int envId, void * pvApiCtx)
28 int eId = OptionsHelper::getEnvId();
33 CheckOutputArgument(pvApiCtx, 1, 1);
35 ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(eId);
36 ScilabGatewayOptions & options = env.getGatewayOptions();
37 OptionsHelper & helper = env.getOptionsHelper();
38 ScilabObjects::initialization(env, pvApiCtx);
40 if (!OptionsHelper::getCopyOccured()) // if the function is called outside a method context, then return null
42 //TODO: get null for environment
43 ScilabObjects::unwrap(0, Rhs + 1, eId, pvApiCtx);
51 OptionsHelper::setCopyOccured(false);
53 if (!options.getMethodName())
63 err = getVarAddressFromPosition(pvApiCtx, 1, &addr);
66 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
69 if (ScilabObjects::isExternalVoid(addr, pvApiCtx))
75 tmpvar = new int[len + 1];
79 for (int i = 0; i < len; i++)
81 err = getVarAddressFromPosition(pvApiCtx, i + 1, &addr);
84 ScilabObjects::removeTemporaryVars(eId, tmpvar);
87 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
92 args[i] = ScilabObjects::getArgumentId(addr, tmpvar, false, false, eId, pvApiCtx);
94 catch (ScilabAbstractEnvironmentException & e)
102 if (options.getIsNew())
106 ret = env.newinstance(options.getObjId(), args, len);
108 catch (std::exception & e)
110 options.setIsNew(false);
111 ScilabObjects::removeTemporaryVars(eId, tmpvar);
117 options.setIsNew(false);
118 ScilabObjects::removeTemporaryVars(eId, tmpvar);
121 options.setMethodName(0);
123 if (ret == VOID_OBJECT)
132 ScilabObjects::createEnvironmentObjectAtPos(EXTERNAL_OBJECT, Rhs + 1, ret, eId, pvApiCtx);
134 catch (ScilabAbstractEnvironmentException & e)
136 env.removeobject(ret);
149 sret = env.invoke(options.getObjId(), options.getMethodName(), args, len);
151 catch (std::exception & e)
153 ScilabObjects::removeTemporaryVars(eId, tmpvar);
156 options.setMethodName(0);
161 ScilabObjects::removeTemporaryVars(eId, tmpvar);
164 options.setMethodName(0);
166 if (!sret || *sret <= 0 || (*sret == 1 && sret[1] == VOID_OBJECT))
178 if (helper.getAutoUnwrap())
180 for (int i = 1; i <= *sret; i++)
182 if (!ScilabObjects::unwrap(sret[i], Rhs + i, eId, pvApiCtx))
186 ScilabObjects::createEnvironmentObjectAtPos(EXTERNAL_OBJECT, Rhs + i, sret[i], eId, pvApiCtx);
188 catch (ScilabAbstractEnvironmentException & e)
190 for (int j = 1; j <= *sret; j++)
192 env.removeobject(sret[j]);
200 env.removeobject(sret[i]);
208 for (int i = 1; i <= *sret; i++)
212 ScilabObjects::createEnvironmentObjectAtPos(EXTERNAL_OBJECT, Rhs + i, sret[i], eId, pvApiCtx);
214 catch (ScilabAbstractEnvironmentException & e)
216 for (int j = 1; j <= *sret; j++)
218 env.removeobject(sret[j]);