3 // Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
4 // Copyright (C) 2011 - INRIA - Serge Steer
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 // See the file ../license.txt
24 function [%ll,%ierr] = script2var(%txt, %ll)
25 //** [%scicos_context, ierr] = script2var(context, %scicos_context)
26 //** context is the scs_m.props.context (string array) associated with the current level
27 //** %scicos_context is a struct containing the values defined by the
31 //local variable names are prefixed with a % to limit conflicts with
32 //variables defined in %txt instructions
35 //next lines checks if variable defined in %ll struct can be evaluated
37 %mm = fieldnames(%ll)';
39 if execstr(%mi+"=%ll(%mi)","errcatch")<>0 then
40 mprintf("%s\n",lasterror())
45 [%ll,%ierr] = getvardef(%txt,%ll)
46 if %ierr<>0 then return, end
49 //**--------------------------------------------------------------------------
50 function [%ll,%ierr]=getvardef(%txt,%ll)
51 //extend and modify the %scicos_context variable (%ll) with the variable
52 //defined in the current level scs_m.props.context (%txt) instructions
54 //local variable names are prefixed with a % to limit conflicts with
55 //variables defined in %txt instructions
57 %ierr = 0; // to make sure %ierr does not enter the difference
58 if isempty(%txt) then return,end
60 %ierr = execstr(%txt,"errcatch");
61 if %ierr<>0 then mprintf("%s\n",lasterror()), return,end
63 // Use 'macrovar' to extract the variable names present in %txt: listvar(5) contains all the output variables of the context
64 clear("foo"); // Locally reserve the "foo" name to avoid redefinition warning
66 listvar = macrovar(foo);
68 // In case clear() has been used in the context, remove its arguments
70 %mm(~isdef(%mm, "l")) = [];
75 mprintf(_("The variable name %s cannot be used as block parameter: ignored\n"),"scs_m");
77 elseif %mi=="ans" then
84 if typeof(%v)=="scs_m" then
85 mprintf(_("The variable name %s cannot be used as block parameter: ignored\n"),"scs_m")
87 elseif or(type(%v)==[11 13 14]) then