re: Rust in s&box
Theoretically you can compile a
cdylib target w/ Rust and link against it dynamically in C#, or any other .net runtime.
Beware though, like you mentioned, you’ll be stuck writing a bunch of glue code to interact w/ C# in Rust and vice-versa. Probably more work than it’s worth- but the rust ecosystem is ripe with tooling around automatic bindings generation. I found a crate that can spit out C# bindings via some Rust macros.
The problem is you’re going to be stuck with writing safe wrappers around C# and s&box implemented constructs anyways. Structures you want to pass down to C# and vice-versa have to be c-compatible which makes your rust code ugly. Managing memory is also a concern, given that .NEt uses a GC and rust’s memory model is unmanaged. On a more optimistic note, the community could maintain a crate (much like the web-sys and js-sys) that provides bindings for s&box-related constructs.
Most of the same issues would be present in trying to link any other compiled language to the game’s runtime. To run an interpreted language like Lua or JS, you’d have to get that running via a native binding, then somehow load scripts in that environment after initializing said interpreter. Maybe there are some C#-native interpreters for these languages but you’d probably outweigh any benefits of writing in those languages with the speed implications of running a half-baked implemented interpreter.
I imagine all these ideas would “just work” on the server- there are obviously security issues with being able to send that down and load blob binaries on the client.
On that note, I think it’d be worthwhile to look at implementing a WebAssembly (WASM) runtime. This would allow both servers and clients to execute binary-compiled code (from many languages) at god-speed and in a sandbox. You wouldn’t be able to access system threads, filesystems, or traditional tcp/udp network stacks, but I think it’d be a great asset when you need to crunch a lot of numbers or do some normally-expensive routines (… like flood-filling, path-finding, image manipulation, etc). Wasmtime is picking great traction and there’s even some work done to spawn an engine in .net (google Wasmtime and wasmtime-dotnet, sorry- reached the max links allowed for my first post!)