Skip to content

Commit dbb19c6

Browse files
committed
More setting inp variable work
1 parent 370b512 commit dbb19c6

File tree

1 file changed

+43
-29
lines changed

1 file changed

+43
-29
lines changed

src/pages/New.vue

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,37 @@ export default {
119119
runCode() {
120120
plugin().then(() => {
121121
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+
}
123136
});
124137
});
125138
},
126139
typeString(vr) {
127-
if(vr === "" || vr == null) {
140+
if (vr === "" || vr == null) {
128141
return null;
129142
}
130143
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]";
139153
}
140154
},
141155
beforeMount() {
@@ -162,34 +176,34 @@ export default {
162176
},
163177
computed: {
164178
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;
167183
}
168184
169185
// bad way to see if multiple lines - fix if possible
170186
else if (this.inputL.includes("\n")) {
171-
console.log('got here');
172-
newArr = '[';
187+
var newArr = "[";
173188
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);
176191
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 + ",";
185201
}
186202
});
187-
newArr = newArr + ']';
203+
newArr = newArr + "]";
188204
return newArr;
189-
}
190-
191-
else {
192-
// type them correctly
205+
} else {
206+
// type them correctly if numbers or strings
193207
return this.typeString(this.inputL);
194208
}
195209
}

0 commit comments

Comments
 (0)