This commit is contained in:
Timothy J. Baek 2024-05-16 19:22:10 -10:00
parent 8f8ce26948
commit 4efb8638ff

View File

@ -138,18 +138,14 @@
}; };
const executePython = async (code) => { const executePython = async (code) => {
result = null;
stdout = null;
stderr = null;
executed = true; executed = true;
let pyodide = await loadPyodide({ let pyodide = await loadPyodide({
indexURL: '/pyodide/', indexURL: '/pyodide/',
stderr: (text) => {
console.log('An error occured:', text);
if (stderr) {
stderr += `${text}\n`;
} else {
stderr = `${text}\n`;
}
},
stdout: (text) => { stdout: (text) => {
console.log('Python output:', text); console.log('Python output:', text);
@ -158,14 +154,22 @@
} else { } else {
stdout = `${text}\n`; stdout = `${text}\n`;
} }
},
stderr: (text) => {
console.log('An error occured:', text);
if (stderr) {
stderr += `${text}\n`;
} else {
stderr = `${text}\n`;
}
} }
}); });
result = pyodide.runPython(code); result = pyodide.runPython(code);
console.log(result); console.log(result);
console.log(stderr);
console.log(stdout); console.log(stdout);
console.log(stderr);
}; };
$: highlightedCode = code ? hljs.highlightAuto(code, hljs.getLanguage(lang)?.aliases).value : ''; $: highlightedCode = code ? hljs.highlightAuto(code, hljs.getLanguage(lang)?.aliases).value : '';