Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions CSharpWasmExpo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,31 @@ const parseMethods = (methods) => {

const bindingsFunctions = {};

const frame = document.querySelector("iframe");
const wasmScope = frame?.contentWindow;

for (const name of methodList) {
try {
bindingsFunctions[name] = eval(name);
let fn =
globalThis[name] ??
wasmScope?.[name] ??
wasmScope?.[`_CPP_${name}`];

if (typeof fn !== "function") {
const sklibMatch = Object.keys(wasmScope || {}).find(
(key) => key === `__sklib__${name}` || key.startsWith(`__sklib__${name}__`)
);

if (sklibMatch && typeof wasmScope[sklibMatch] === "function") {
fn = wasmScope[sklibMatch];
}
}

if (typeof fn === "function") {
bindingsFunctions[name] = fn;
} else {
console.warn(`Missing binding: ${name}`);
}
} catch (e) {
console.warn(e);
}
Expand Down Expand Up @@ -68,4 +90,4 @@ const CompileAndRun = async (code, reportError) => {
// This event will be trigger by the csharp compiler
document.addEventListener("compileAndRun", (ev) => {
CompileAndRun(ev.detail.program[0].source, ev.detail.reportError);
});
});
Loading