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">
|
|
|
|
<button class="demo-button negative" style="margin: 8px 8px" onclick="clearInput(); return false;">
|
|
|
|
Clear Input
|
|
|
|
</button>
|
|
|
|
<button class="demo-button positive" onclick="executeScript(); return false;">
|
|
|
|
Run
|
|
|
|
</button>
|
|
|
|
</div>
|
2021-11-11 00:40:46 +08:00
|
|
|
</div>
|
|
|
|
<div>
|
2021-12-16 01:23:26 +08:00
|
|
|
<!-- centered header saying Output -->
|
|
|
|
<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>
|
2021-12-16 01:23:26 +08:00
|
|
|
<div class="button-group">
|
|
|
|
<button class="demo-button negative" onclick="clearOutput(); return false;">
|
|
|
|
Clear Output
|
|
|
|
</button>
|
|
|
|
</div>
|
2021-11-11 00:40:46 +08:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
2021-12-16 01:23:26 +08:00
|
|
|
<!-- Styles for editor -->
|
|
|
|
<style>
|
|
|
|
.button-group {
|
|
|
|
display: flex;
|
|
|
|
justify-content: right;
|
|
|
|
}
|
|
|
|
|
|
|
|
.header-center {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.demo-button {
|
|
|
|
color: white;
|
|
|
|
padding: 14px 20px;
|
|
|
|
margin: 8px 0;
|
|
|
|
border: none;
|
|
|
|
cursor: pointer;
|
|
|
|
width: 30%;
|
|
|
|
display: inline;
|
|
|
|
}
|
|
|
|
|
|
|
|
.demo-button-rightmost {
|
|
|
|
margin: inherit 2px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.positive {
|
|
|
|
background-color: #4CAF50;
|
|
|
|
}
|
|
|
|
|
|
|
|
.negative {
|
|
|
|
background-color: #f44336;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<!-- Luau WASM (async fetch) -->
|
|
|
|
<script async src="https://github.com/Roblox/luau/releases/latest/download/Luau.Web.js"></script>
|
|
|
|
<!-- CodeMirror -->
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.32.0/codemirror.min.js"></script>
|
|
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.32.0/codemirror.min.css" />
|
|
|
|
<!-- 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");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Misc Functions
|
2021-11-11 00:40:46 +08:00
|
|
|
function output(text) {
|
2021-12-16 01:23:26 +08:00
|
|
|
output_box = document.getElementById("output");
|
|
|
|
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 clearInput() {
|
2021-12-16 01:23:26 +08:00
|
|
|
editor.setValue("");
|
2021-11-11 00:40:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function clearOutput() {
|
|
|
|
document.getElementById("output").value = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
function executeScript() {
|
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) {
|
|
|
|
output('Error:' + err.replace('stdin:', ''));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|