@@ -119,23 +119,37 @@ export default {
119
119
runCode () {
120
120
plugin ().then (() => {
121
121
pyodide .loadPackage ([" numpy" ]).then (() => {
122
- this .outputL = pyodide .runPython (newCode);
122
+ // if there is a variable to set
123
+ if (this .realInput ) {
124
+ if (this .isString (this .realInput )) {
125
+ this .outputL = pyodide .runPython (
126
+ " inp='" + this .realInput + " '\n " + this .codeL
127
+ );
128
+ } else {
129
+ this .outputL = pyodide .runPython (
130
+ " inp=" + this .realInput + " \n " + this .codeL
131
+ );
132
+ }
133
+ } else {
134
+ this .outputL = pyodide .runPython (this .codeL );
135
+ }
123
136
});
124
137
});
125
138
},
126
139
typeString (vr ) {
127
- if (vr === " " || vr == null ) {
140
+ if (vr === " " || vr == null ) {
128
141
return null ;
129
142
}
130
143
if (vr .match (/ ^ [+-] ? \d + $ / )) {
131
- return parseInt (vr);
132
- }
133
- else if (vr .match (/ ^ [+-] ? \d + (\. \d + )? $ / )) {
134
- return parseFloat (vr);
135
- }
136
- else {
137
- return vr;
138
- }
144
+ return parseInt (vr);
145
+ } else if (vr .match (/ ^ [+-] ? \d + (\. \d + )? $ / )) {
146
+ return parseFloat (vr);
147
+ } else {
148
+ return vr;
149
+ }
150
+ },
151
+ isString (vr ) {
152
+ return Object .prototype .toString .call (vr) === " [object String]" ;
139
153
}
140
154
},
141
155
beforeMount () {
@@ -162,34 +176,34 @@ export default {
162
176
},
163
177
computed: {
164
178
realInput : function () {
165
- if (this .inputL == null ) {
166
- return " " ;
179
+ // currently not supporting numbers being strings
180
+
181
+ if (this .inputL == null ) {
182
+ return null ;
167
183
}
168
184
169
185
// bad way to see if multiple lines - fix if possible
170
186
else if (this .inputL .includes (" \n " )) {
171
- console .log (' got here' );
172
- newArr = ' [' ;
187
+ var newArr = " [" ;
173
188
174
- this .inputL .split (' \n ' ).forEach (function (element ) {
175
- inp = this .typeString (element);
189
+ this .inputL .split (" \n " ).forEach (function (element ) {
190
+ var inp = this .typeString (element);
176
191
177
- if (inp == null ) {
178
- return " " ;
179
- }
180
- else if (typeof inp === ' string' || inp instanceof String ) {
181
- newArr = newArr + ' \' ' + inp + ' \' ,' ;
182
- }
183
- else {
184
- newArr = newArr + inp + ' ,' ;
192
+ if (inp == null ) {
193
+ return null ;
194
+ } else if (
195
+ // check if string
196
+ this .isString (inp)
197
+ ) {
198
+ newArr = newArr + " '" + inp + " '," ;
199
+ } else {
200
+ newArr = newArr + inp + " ," ;
185
201
}
186
202
});
187
- newArr = newArr + ' ] ' ;
203
+ newArr = newArr + " ] " ;
188
204
return newArr;
189
- }
190
-
191
- else {
192
- // type them correctly
205
+ } else {
206
+ // type them correctly if numbers or strings
193
207
return this .typeString (this .inputL );
194
208
}
195
209
}
0 commit comments