move demo repl to docs

This commit is contained in:
Pelanyo Kamara 2021-11-08 15:38:30 +00:00
parent bb987daf19
commit 24b78c4a80
No known key found for this signature in database
GPG key ID: 1C8B9C40A2527035
5 changed files with 63 additions and 64 deletions

View file

@ -1,60 +0,0 @@
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Luau Web REPL</title>
</head>
<body>
<div>
<label>Script:</label>
<br>
<textarea rows="10" cols="70" id="script"></textarea>
<br><br>
<button onclick="clearInput()">
Clear Input
</button>
<button onclick="executeScript()">
Run
</button>
</div>
<br><br>
<div>
<label>Output:</label>
<br>
<textarea readonly rows="10" cols="70" id="output"></textarea>
<br><br>
<button onclick="clearOutput()">
Clear Output
</button>
</div>
<script>
function output(text) {
document.getElementById("output").value += new Date().toLocaleTimeString() + ": " + text + "\n";
}
var Module = {
'print': function (msg) { output(msg) },
'printErr': function (err) { output(err) } // potentially unused?
};
function clearInput() {
document.getElementById("script").value = "";
}
function clearOutput() {
document.getElementById("output").value = "";
}
function executeScript() {
try {
Module.ccall('executeScript', null, ['string'], [document.getElementById("script").value]);
}
catch (e) {
output(Module.ccall('getExceptionFromPtr', 'string', ['number'], [e]).replace('stdin', '[ERROR]'));
}
}
</script>
<script async src="luau/Luau.Repl.Web.js"></script>
</body>
</html>

View file

@ -40,11 +40,8 @@ if(LUAU_BUILD_WEB_REPL AND EMSCRIPTEN)
# declare exported functions to emscripten
target_link_options(Luau.Repl.Web PRIVATE -sEXPORTED_FUNCTIONS=['_getExceptionFromPtr','_executeScript'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap'] -sNO_DISABLE_EXCEPTION_CATCHING)
# copy html directory
add_custom_command(TARGET Luau.Repl.Web PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/CLI/html ${CMAKE_BINARY_DIR}/webrepl)
# custom output directory for webm + js file
set_target_properties(Luau.Repl.Web PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/webrepl/luau)
set_target_properties(Luau.Repl.Web PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/docs/assets/luau)
else()
if(LUAU_BUILD_CLI)
add_executable(Luau.Repl.CLI)

View file

@ -25,3 +25,5 @@ pages:
url: /profile
- title: Library
url: /library
- title: Demo
url: /demo

53
docs/_includes/repl.html Normal file
View file

@ -0,0 +1,53 @@
<form>
<div>
<label>Script:</label>
<br>
<textarea rows="10" cols="70" id="script">print("Hello World!")</textarea>
<br><br>
<button onclick="clearInput(); return false;">
Clear Input
</button>
<button onclick="executeScript(); return false;">
Run
</button>
</div>
<br><br>
<div>
<label>Output:</label>
<br>
<textarea readonly rows="10" cols="70" id="output"></textarea>
<br><br>
<button onclick="clearOutput(); return false;">
Clear Output
</button>
</div>
</form>
<script>
function output(text) {
document.getElementById("output").value += new Date().toLocaleTimeString() + ": " + text + "\n";
}
var Module = {
'print': function (msg) { output(msg) },
'printErr': function (err) { } // potentially unused?
};
function clearInput() {
document.getElementById("script").value = "";
}
function clearOutput() {
document.getElementById("output").value = "";
}
function executeScript() {
try {
Module.ccall('executeScript', null, ['string'], [document.getElementById("script").value]);
}
catch (e) {
output(Module.ccall('getExceptionFromPtr', 'string', ['number'], [e]).replace('stdin', '[ERROR]'));
}
}
</script>
<script async src="assets/luau/Luau.Repl.Web.js"></script>

7
docs/_pages/demo.md Normal file
View file

@ -0,0 +1,7 @@
---
permalink: /demo
title: Demo
toc: true
---
{% include repl.html %}