From a6b18eefa012bec0036ebbad3df6fbe920f107b8 Mon Sep 17 00:00:00 2001 From: Arnold Date: Sun, 12 Apr 2026 08:04:09 +1000 Subject: [PATCH 1/3] Improve C# WASM runtime binding loading and logging --- CSharpWasm/SplashKitBindings.Generated.cs | 3 +++ CSharpWasmExpo/main.js | 23 ++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CSharpWasm/SplashKitBindings.Generated.cs b/CSharpWasm/SplashKitBindings.Generated.cs index 75fb5b64..417f10fd 100644 --- a/CSharpWasm/SplashKitBindings.Generated.cs +++ b/CSharpWasm/SplashKitBindings.Generated.cs @@ -110,6 +110,9 @@ public partial class SplashKit [JSImport("SplashKitBackendWASM.clear_screen", "main.js")] public static partial void ClearScreen(); + [JSImport("SplashKitBackendWASM.draw_circle", "main.js")] + public static partial void DrawCircle(int color, double x, double y, double radius); + [JSImport("SplashKitBackendWASM.refresh_screen", "main.js")] public static partial void RefreshScreen(); diff --git a/CSharpWasmExpo/main.js b/CSharpWasmExpo/main.js index b8b414d6..486c4019 100644 --- a/CSharpWasmExpo/main.js +++ b/CSharpWasmExpo/main.js @@ -2,6 +2,11 @@ import { dotnet } from "./wwwroot/_framework/dotnet.js"; import methods from "./splashKitMethods.generated.js"; const parseMethods = (methods) => { + if (!methods || typeof methods !== "string") { + console.error("[SplashKit WASM] Invalid method list received."); + return {}; + } + const methodList = methods .split(",") .map((method) => method.trim().replace("\n", "")) @@ -11,9 +16,13 @@ const parseMethods = (methods) => { for (const name of methodList) { try { - bindingsFunctions[name] = eval(name); + if (typeof window[name] === "function") { + bindingsFunctions[name] = window[name]; + } else { + console.warn(`[SplashKit WASM] Missing function: ${name}`); + } } catch (e) { - console.warn(e); + console.warn(`[SplashKit WASM] Error loading function: ${name}`, e); } } @@ -28,6 +37,14 @@ const loadDotNet = async () => { const skFunctions = parseMethods(methods); + skFunctions.process_events = () => { + if (typeof __sko_process_events === "function") { + return __sko_process_events(); + } + + console.warn("[SplashKit WASM] process_events is not wired properly."); + }; + setModuleImports("main.js", { window: { location: { @@ -68,4 +85,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); -}); +}); \ No newline at end of file From 99bfd09d14023b7a4a5ae5bcb5c00b718c54ac81 Mon Sep 17 00:00:00 2001 From: Arnold Date: Fri, 8 May 2026 21:07:04 +1000 Subject: [PATCH 2/3] Remove generated binding changes and improve warning handling --- CSharpWasm/SplashKitBindings.Generated.cs | 3 -- CSharpWasmExpo/main.js | 37 +++++++++++++++++++++-- SplashkitOnline.sln | 24 +++++++++++++++ 3 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 SplashkitOnline.sln diff --git a/CSharpWasm/SplashKitBindings.Generated.cs b/CSharpWasm/SplashKitBindings.Generated.cs index 417f10fd..75fb5b64 100644 --- a/CSharpWasm/SplashKitBindings.Generated.cs +++ b/CSharpWasm/SplashKitBindings.Generated.cs @@ -110,9 +110,6 @@ public partial class SplashKit [JSImport("SplashKitBackendWASM.clear_screen", "main.js")] public static partial void ClearScreen(); - [JSImport("SplashKitBackendWASM.draw_circle", "main.js")] - public static partial void DrawCircle(int color, double x, double y, double radius); - [JSImport("SplashKitBackendWASM.refresh_screen", "main.js")] public static partial void RefreshScreen(); diff --git a/CSharpWasmExpo/main.js b/CSharpWasmExpo/main.js index 486c4019..76f42349 100644 --- a/CSharpWasmExpo/main.js +++ b/CSharpWasmExpo/main.js @@ -13,19 +13,49 @@ const parseMethods = (methods) => { .filter(Boolean); const bindingsFunctions = {}; + const missingFunctions = []; + const errorFunctions = []; for (const name of methodList) { try { if (typeof window[name] === "function") { bindingsFunctions[name] = window[name]; } else { - console.warn(`[SplashKit WASM] Missing function: ${name}`); + missingFunctions.push(name); } } catch (e) { - console.warn(`[SplashKit WASM] Error loading function: ${name}`, e); + errorFunctions.push(name); } } + if (missingFunctions.length > 0) { + console.warn( + `[SplashKit WASM] ${missingFunctions.length} SplashKit bindings are missing.` + ); + + console.groupCollapsed("[SplashKit WASM] View missing bindings"); + + missingFunctions.forEach((name) => { + console.warn(name); + }); + + console.groupEnd(); + } + + if (errorFunctions.length > 0) { + console.warn( + `[SplashKit WASM] ${errorFunctions.length} SplashKit bindings could not be loaded.` + ); + + console.groupCollapsed("[SplashKit WASM] View binding loading errors"); + + errorFunctions.forEach((name) => { + console.warn(name); + }); + + console.groupEnd(); + } + return bindingsFunctions; }; @@ -63,12 +93,14 @@ const CompileAndRun = async (code, reportError) => { try { const exports = await loadDotNet(); const result = await exports.CSharpCodeRunner.CompileAndRun(code); + if (result.includes("Compilation failed")) { const errors = result.split(":"); const errorLine = errors[1].split("Line"); const indexCorrector = 1; const filePath = "__USERCODE__/code/main.cs"; + reportError( filePath, result, @@ -82,7 +114,6 @@ 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); }); \ No newline at end of file diff --git a/SplashkitOnline.sln b/SplashkitOnline.sln new file mode 100644 index 00000000..07a12b69 --- /dev/null +++ b/SplashkitOnline.sln @@ -0,0 +1,24 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.2.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpWasm", "CSharpWasm\CSharpWasm.csproj", "{AE9F4148-836C-AACC-65B5-39898F5D8EAD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AE9F4148-836C-AACC-65B5-39898F5D8EAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AE9F4148-836C-AACC-65B5-39898F5D8EAD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AE9F4148-836C-AACC-65B5-39898F5D8EAD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AE9F4148-836C-AACC-65B5-39898F5D8EAD}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {495E96FC-C3F1-42BB-B40D-B6457AD35351} + EndGlobalSection +EndGlobal From f374a9e23e3da36ee688e5869c1c901911ec3072 Mon Sep 17 00:00:00 2001 From: Arnold-Seb Date: Fri, 8 May 2026 21:30:17 +1000 Subject: [PATCH 3/3] Delete SplashkitOnline.sln --- SplashkitOnline.sln | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 SplashkitOnline.sln diff --git a/SplashkitOnline.sln b/SplashkitOnline.sln deleted file mode 100644 index 07a12b69..00000000 --- a/SplashkitOnline.sln +++ /dev/null @@ -1,24 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.5.2.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpWasm", "CSharpWasm\CSharpWasm.csproj", "{AE9F4148-836C-AACC-65B5-39898F5D8EAD}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AE9F4148-836C-AACC-65B5-39898F5D8EAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AE9F4148-836C-AACC-65B5-39898F5D8EAD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AE9F4148-836C-AACC-65B5-39898F5D8EAD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AE9F4148-836C-AACC-65B5-39898F5D8EAD}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {495E96FC-C3F1-42BB-B40D-B6457AD35351} - EndGlobalSection -EndGlobal