2021-11-11 00:40:46 +08:00
|
|
|
<form>
|
|
|
|
<div>
|
2021-12-16 01:23:26 +08:00
|
|
|
<label class="header-center"><b>Input</b></label>
|
2021-11-11 00:40:46 +08:00
|
|
|
<br>
|
2021-12-16 01:23:26 +08:00
|
|
|
<textarea rows="10" cols="70" id="script"></textarea>
|
|
|
|
<div class="button-group">
|
2021-12-21 07:36:41 +08:00
|
|
|
<button onclick="executeScript(); return false;" class="demo-button">Run</button>
|
2021-12-21 07:40:38 +08:00
|
|
|
<input type="checkbox" checked="true" class="demo-button" id="output-clear" />
|
|
|
|
<label for="output-clear">Clear Output</label>
|
2021-12-16 01:23:26 +08:00
|
|
|
</div>
|
2021-11-11 00:40:46 +08:00
|
|
|
</div>
|
|
|
|
<div>
|
2021-12-16 01:23:26 +08:00
|
|
|
<label class="header-center"><b>Output</b></label>
|
2021-11-11 00:40:46 +08:00
|
|
|
<br>
|
|
|
|
<textarea readonly rows="10" cols="70" id="output"></textarea>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
2021-12-16 01:23:26 +08:00
|
|
|
<!-- Styles for editor -->
|
|
|
|
<style>
|
|
|
|
.header-center {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.demo-button {
|
2021-12-21 07:36:41 +08:00
|
|
|
padding: 7px 7px;
|
|
|
|
vertical-align: middle;
|
2021-12-16 01:23:26 +08:00
|
|
|
}
|
2021-12-21 07:36:41 +08:00
|
|
|
.line-error {
|
|
|
|
background: #e65f55;
|
2021-12-16 01:23:26 +08:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<!-- Luau WASM (async fetch) -->
|
|
|
|
<script async src="https://github.com/Roblox/luau/releases/latest/download/Luau.Web.js"></script>
|
|
|
|
<!-- CodeMirror -->
|
2021-12-21 07:36:41 +08:00
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.0/codemirror.min.js"></script>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.0/addon/edit/matchbrackets.min.js"></script>
|
|
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.0/codemirror.min.css" />
|
2021-12-16 01:23:26 +08:00
|
|
|
<!-- Luau Parser for CodeMirror -->
|
|
|
|
<script src="assets/js/luau_mode.js"></script>
|
|
|
|
<!-- CodeMirror Luau Editor (MUST BE LOADED AFTER CODEMIRROR!) -->
|
2021-11-11 00:40:46 +08:00
|
|
|
<script>
|
2021-12-16 01:23:26 +08:00
|
|
|
var editor = CodeMirror.fromTextArea(document.getElementById("script"), {
|
|
|
|
theme: "default",
|
|
|
|
mode: "luau",
|
|
|
|
matchBrackets: true,
|
|
|
|
lineNumbers: true,
|
|
|
|
smartIndent: true,
|
|
|
|
indentWithTabs: true,
|
|
|
|
indentUnit: 4,
|
|
|
|
});
|
|
|
|
editor.setValue("print(\"Hello World!\")\n");
|
|
|
|
editor.addKeyMap({
|
|
|
|
"Ctrl-Enter": function(cm) {
|
|
|
|
executeScript();
|
|
|
|
},
|
|
|
|
"Shift-Tab": function (cm) {
|
|
|
|
// dedent functionality
|
|
|
|
cm.execCommand("indentLess");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-12-21 07:36:41 +08:00
|
|
|
var lastError = undefined;
|
|
|
|
|
2021-11-11 00:40:46 +08:00
|
|
|
function output(text) {
|
2021-12-21 07:36:41 +08:00
|
|
|
var output_box = document.getElementById("output");
|
2021-12-16 01:23:26 +08:00
|
|
|
output_box.value += text.replace('stdin:', '') + "\n";
|
|
|
|
// scroll to bottom
|
|
|
|
output_box.scrollTop = output_box.scrollHeight;
|
2021-11-11 00:40:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var Module = {
|
|
|
|
'print': function (msg) { output(msg) }
|
|
|
|
};
|
|
|
|
|
|
|
|
function executeScript() {
|
2021-12-21 07:36:41 +08:00
|
|
|
if (lastError) {
|
|
|
|
editor.removeLineClass(lastError, "background", "line-error");
|
|
|
|
lastError = undefined;
|
|
|
|
}
|
|
|
|
|
2021-12-21 07:44:51 +08:00
|
|
|
var output_clear = document.getElementById("output-clear");
|
|
|
|
if (output_clear.checked) {
|
|
|
|
var output_box = document.getElementById("output");
|
|
|
|
output_box.value = '';
|
|
|
|
}
|
|
|
|
|
2021-12-16 01:23:26 +08:00
|
|
|
var err = Module.ccall('executeScript', 'string', ['string'], [editor.getValue()]);
|
2021-11-11 00:40:46 +08:00
|
|
|
if (err) {
|
2021-12-21 07:36:41 +08:00
|
|
|
var err_text = err.replace('stdin:', '');
|
|
|
|
output('Error:' + err_text);
|
|
|
|
|
|
|
|
var err_line = parseInt(err_text);
|
|
|
|
if (err_line) {
|
|
|
|
lastError = editor.addLineClass(err_line-1, "background", "line-error");
|
|
|
|
}
|
2021-11-11 00:40:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|