Hey everyone! I'm developing a moddable game and I've chosen to use C# compiled to WebAssembly (WASM) for mods. I'm curious if there's a way to enforce that users can only use C# with WASM and not other languages that compile to it. The idea here is that it would make it easier for users who want to refer to other open-source mods. I understand this kind of goes against the flexibility of WASM, but I'm struggling to find a good language that meets static type safety, sandboxing, and supports object-oriented or procedural programming. Any thoughts?
4 Answers
It's kind of like saying you can only use TypeScript for JavaScript on your website; it just doesn’t work that way. Instead, consider laying out clear expectations in your API so it maintains certain structures, but allow for different languages to interact with it.
Unfortunately, you can't really enforce a single language when it comes to WASM. Each language that compiles to WASM should function the same way, so it wouldn't matter if it's C# or anything else. The underlying WASM code is just an instruction set that doesn’t differentiate the origin, similar to how CSS can come from different pre-processors and it's still CSS at the end.
You can't impose restrictions directly in the WASM layer itself. The solution is mostly about controlling the environment where the WASM modules run. If you ship your game with a specific C# toolchain and make your mod loader check for that, you'd effectively guide users to stick to C#. This way, you retain the benefits of WASM while limiting the languages used.
Nope, that restriction isn't really feasible. You might think about adding some metadata to your WASM modules to indicate they were compiled from C#, but that can be easily bypassed. Plus, if users have the freedom to choose their language, they'll usually pick what they know. Forcing them to switch might just turn them away altogether. Instead, just focus your documentation on C# to guide them!
Related Questions
Interactive Wheel Spinner Tool – Add Choices and Randomly Pick a Winner
Raffle Ticket Generator
Instant Online Dice Roller
Sudoku Solver
Tambola Number Generator
Tambola Ticket Generator