Re:Rust: Enable WebAssembly backend by default
by steveklabnik on Sunday November 26, 2017 @01:29PM
(#15782243)
You're considering the "call into C" case, which is only half the story. "C calls into you" will always be easier in C++ and Rust, or any other language with "no" runtime, than heavier languages that rely on them. Yes, it can work, but it's a disadvantage.
[ Parent
| on HN ]
Re:Rust: Enable WebAssembly backend by default
by Const-me on Sunday November 26, 2017 @01:56PM
(#15782359)
In C# I use callbacks where I find appropriate (logging, also some rare events). Under the hood, the runtime marshals delegates (most languages would call them lambdas) into unmanaged C function pointers.
Ease of use is the same when I consuming the C API from e.g. C++. No disadvantage for C#.
Re:Rust: Enable WebAssembly backend by default
by sinhpham on Sunday November 26, 2017 @02:16PM
(#15782465)
"C calls into you" means you already have a C code base and now need to call your C# functions.
Re:Rust: Enable WebAssembly backend by default
by Const-me on Sunday November 26, 2017 @02:35PM
(#15782549)
Right, C# is OK when C code calls into it.
Re:Rust: Enable WebAssembly backend by default
by int_19h on Monday November 27, 2017 @12:00AM
(#15784960)
One neat trick with .NET on Windows, is that you can actually export static methods in assemblies as unmanaged entry points. In other words, things can LoadLibrary/GetProcAddress them, and invoke them as native.
C# doesn't support this out of the box, but it can be easily done by post-processing the generated assembly. There's a NuGet package for that.
https://www.nuget.org/packages/UnmanagedExports
I'm not sure if any of that works on other platforms, or with .NET Core. Probably not.
Re:Rust: Enable WebAssembly backend by default
by Const-me on Monday November 27, 2017 @08:09AM
(#15786978)
I once tried to use that trick, for nVidia optimus integration.
Didn’t work because that recompilation step broke debugger, and invalidated .PDB debug symbols.
Re:Rust: Enable WebAssembly backend by default
by steveklabnik on Sunday November 26, 2017 @05:01PM
(#15783278)
To be clear, I’m not saying it’s not possible. I’m saying that one less runtime is an advantage.