-
Notifications
You must be signed in to change notification settings - Fork 0
/
online.html
93 lines (77 loc) · 2.78 KB
/
online.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html dir="rtl" lang="en_US">
<head>
<title>Sialk Programming Language</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<textarea dir="rtl" id="code" rows="20" cols="40">تابع سیلک {
نمایش "سیلک، دنیا!"
}
</textarea>
<br>
<button id="execute" disabled="true">اجرا</button>
<pre></pre>
<script>
const codeTextArea = document.querySelector('#code');
const executeButton = document.querySelector('#execute');
const outputPre = document.querySelector('pre');
const args = ['--code', ''];
let isReady = false;
var Module = {
noInitialRun: true,
onRuntimeInitialized: () => {
console.log('Sialk loaded successfully');
isReady = true;
executeButton.disabled = false;
if (codeTextArea.value.toString().trim() != "") {
runSialk();
}
},
print: (text) => {
console.log(text);
}
};
function captureOutput(arguments) {
if (outputPre) {
outputPre.textContent = '';
}
let output = '';
const originalConsoleLog = console.log;
console.log = function (text) {
output += text + '\n';
};
callMain(arguments);
console.log = originalConsoleLog;
if (outputPre) {
outputPre.textContent = output;
}
return output;
}
function runSialk() {
console.log('Running Sialk code...');
const code = codeTextArea.value.toString().trim();
if (!code) {
alert('Code is empty! Please enter Sialk code.');
return;
}
args[1] = code;
console.log('Calling sialk with arguments:', args);
if (isReady) {
captureOutput(args);
} else {
console.log('Sialk runtime not ready. Please wait...');
}
}
executeButton.addEventListener('click', () => {
console.log('Button clicked!');
runSialk();
});
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'sialk.js';
document.body.appendChild(script);
</script>
</body>
</html>