61 lines
2.1 KiB
HTML
61 lines
2.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Solstice Playground</title>
|
|
<link rel="stylesheet" href="https://sols.dev/index.css">
|
|
<style>
|
|
textarea {
|
|
width: 100%;
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
<body>
|
|
<div class="box">
|
|
<h1>Solstice Playground</h1>
|
|
|
|
<textarea class="code" id="editor" spellcheck="false" placeholder="Enter Solstice code here..." rows="20">
|
|
puts "Hello from Solstice via WebAssembly!"
|
|
</textarea>
|
|
|
|
<div id="controls">
|
|
<button id="runBtn" style="font-size: 20px;">Loading WASM...</button>
|
|
</div>
|
|
|
|
<h3>Output:</h3>
|
|
<pre class="code" id="output">Output will appear here. Click "Run Code" to run!</pre>
|
|
|
|
<script src="playground.js"></script>
|
|
<script>
|
|
const outputDiv = document.getElementById('output');
|
|
const codeArea = document.getElementById('editor');
|
|
const runBtn = document.getElementById('runBtn');
|
|
|
|
// Emscripten provides a 'Module' object that fires 'onRuntimeInitialized'
|
|
Module.onRuntimeInitialized = () => {
|
|
outputDiv.innerText = "Ready to run.";
|
|
runBtn.innerText = "Run";
|
|
|
|
runBtn.addEventListener('click', () => {
|
|
const source = codeArea.value;
|
|
|
|
// Use 'ccall' to call the C function:
|
|
// ccall(name, returnType, [argTypes], [args])
|
|
const result = Module.ccall(
|
|
'solstice_run', // C function name
|
|
'string', // Return type
|
|
['string'], // Argument types
|
|
[source] // Arguments
|
|
);
|
|
|
|
outputDiv.innerText = result;
|
|
});
|
|
};
|
|
</script>
|
|
</div>
|
|
</body>
|
|
</html>
|