-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
109 lines (93 loc) · 3.83 KB
/
script.js
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import createDotnetRuntime, { dotnet, exit } from './dotnet.js'
var displayConsole = false;
function sayHelloCallback(message){
//console.log("message: " + message);
document.getElementById("fromauto").innerText = message;
}
function setCompileLog (log){
//console.log('compile log', log);
if (log.includes('Compilation success'))
log = "<span style='background-color:lightgreen'> Success </span><br>" + log;
else
log = "<span style='background-color:red'> Error </span><br>" + log;
document.getElementById("fromcompileoutput_compiler").innerHTML = log;
displayConsole = false;
}
function setRunLog (log){
//console.log('run log', log);
document.getElementById("fromcompileoutput_runtime").innerHTML = log;
}
function consumeConsoleWriteline (log) {
console.log(log);
if (displayConsole) document.getElementById("fromcompileoutput_results").innerHTML = log;
}
function consumeConsoleError (log) {
console.warn(log);
if (displayConsole) document.getElementById("fromcompileoutput_errors").innerHTML = log;
}
//try {
const { runtimeBuildInfo, setModuleImports, getAssemblyExports, runMain, getConfig } = await dotnet
//.withConsoleForwarding() // executes a websocket connection to /console
.withElementOnExit()
.withModuleConfig({
configSrc: "./mono-config.json",
onConfigLoaded: (config) => {
// This is called during emscripten `dotnet.wasm` instantiation, after we fetched config.
console.log('user code Module.onConfigLoaded');
config.debugLevel = 0;
// config is loaded and could be tweaked before the rest of the runtime startup sequence
//config.environmentVariables["MONO_LOG_LEVEL"] = "debug"
config.environmentVariables["MONO_LOG_LEVEL"] = "info"
},
preInit: () => { console.log('user code Module.preInit'); },
preRun: () => { console.log('user code Module.preRun'); },
onRuntimeInitialized: () => {
console.log('user code Module.onRuntimeInitialized');
// here we could use API passed into this callback
// Module.FS.chdir("/");
},
onDotnetReady: () => {
// This is called after all assets are loaded.
console.log('user code Module.onDotnetReady');
},
postRun: () => { console.log('user code Module.postRun'); },
print: consumeConsoleWriteline,
printErr: consumeConsoleError,
})
.create();
// at this point both emscripten and monoVM are fully initialized.
// we could use the APIs returned and resolved from createDotnetRuntime promise
// both exports are receiving the same object instances
console.log('user code after createDotnetRuntime()');
setModuleImports("script.js", {
WasmRoslyn: {
Program: {
sayHelloCallback,
window: () => globalThis.window,
location: () => globalThis.window.location,
setCompileLog,
setRunLog
}
}
});
const config = getConfig();
var exports = await getAssemblyExports(config.mainAssemblyName);
exports.WasmRoslyn.Program.SayHello();
let exit_code = await runMain(config.mainAssemblyName, []);
//exit(exit_code);
document.getElementById("execute").addEventListener('click', (event) => {
const msg = exports.WasmRoslyn.Program.ExecuteOnDemand();
document.getElementById("frombutton").innerText = msg;
});
document.getElementById("compileandrun").addEventListener('click', (event) => {
displayConsole = true;
setRunLog("");
consumeConsoleWriteline("");
consumeConsoleError("");
exports.WasmRoslyn.Program.Run(document.getElementById("code").value);
});
//}
//catch (err) {
// exit(2, err);
//}
//