Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ out/
splashkit/
generated/
__pycache__/
_framework/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed when running the buildAndCopy.sh script.
It created files in Browser_IDE/CSharpWasm/bin
Is this supposed to be ignored two
Screenshot from 2025-05-16 10-01-40

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, those are the actual libraries that allow compiling C# in the browser :)

Binary file added Browser_IDE/CSharpWasm/bin/CSharpWasm.dll
Binary file not shown.
Binary file added Browser_IDE/CSharpWasm/bin/System.Console.dll
Binary file not shown.
Binary file not shown.
Binary file added Browser_IDE/CSharpWasm/bin/System.Runtime.dll
Binary file not shown.
Binary file added Browser_IDE/CSharpWasm/bin/mscorlib.dll
Binary file not shown.
Binary file added Browser_IDE/CSharpWasm/bin/netstandard.dll
Binary file not shown.
71 changes: 71 additions & 0 deletions Browser_IDE/CSharpWasm/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { dotnet } from "./wwwroot/_framework/dotnet.js";
import methods from "./splashKitMethods.generated.js";

const parseMethods = (methods) => {
const methodList = methods
.split(",")
.map((method) => method.trim().replace("\n", ""))
.filter(Boolean);

const bindingsFunctions = {};

for (const name of methodList) {
try {
bindingsFunctions[name] = eval(name);
} catch (e) {
console.warn(e);
}
}

return bindingsFunctions;
};

const loadDotNet = async () => {
const { setModuleImports, getAssemblyExports, getConfig } = await dotnet
.withDiagnosticTracing(false)
.withApplicationArgumentsFromQuery()
.create();

const skFunctions = parseMethods(methods);

setModuleImports("main.js", {
window: {
location: {
href: () => globalThis.window.location.href,
},
},
SplashKitBackendWASM: skFunctions,
});

const config = getConfig();
const exports = await getAssemblyExports(config.mainAssemblyName);
return exports;
};

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,
Number(errorLine[1]) + indexCorrector,
null,
true,
);
}
} catch (error) {
console.error("Error during code execution:", error);
}
};

// This event will be trigger by the csharp compiler
document.addEventListener("compileAndRun", (ev) => {
CompileAndRun(ev.detail.program[0].source, ev.detail.reportError);
});
Loading
Loading