> module
std::re::dotnet::runtime
host a .NET runtime
std::re::dotnet::runtime starts and drives a .NET runtime inside the Xur process. Assemblies are loaded from disk, from bytes, or straight from a dotnet::Module built in the script, and static methods are called through native function pointers.
Pointers and managed object addresses are plain integers. A Runtime runs on CoreCLR, or on Mono when a script is handed one for a Mono game; the methods below say where the backends differ.
Backed by hao-runtime.
> functions
> types
| Backend::CoreClr | |
| Backend::Mono |
Where to find .NET and which framework version to run.
| dotnet_root | Option<PathBuf> | Defaults to `DOTNET_ROOT` or the standard install locations. |
| framework_version | Option<str> | A `Microsoft.NETCore.App` version such as `9.0.21`. Defaults to the newest installed. |
runtime.attach_thread()Let the calling thread run managed code. Needed on Mono for threads it didn't start; does nothing on CoreCLR.
The major .NET version the runtime was started with, such as 9; None on Mono.
Walk the managed IEnumerable at address obj and return the addresses of its elements. Handles lazy iterators and LINQ chains. On CoreCLR call warm_enumerate() first, and call this on the game's managed thread. On Mono the addresses stay valid only until the next garbage collection.
runtime.find_method_from_loaded(assembly: str, type_name: str, method: str, param_count: i32) -> Result<i64, str>Like method_pointer_from_loaded(), but picks the overload with param_count parameters.
A native pointer to static method method of type_name in assembly. On CoreCLR the method must be [UnmanagedCallersOnly]; on Mono the pointer takes an extra, trailing exception argument.
Call the method pointer ptr with integer (or pointer) arguments and return its integer result. The calling thread is registered with the runtime first.
Like invoke(), for a method that returns a floating-point number.
Load the assembly at path and make it available to later loads by name. On CoreCLR, dependencies next to it are found too.
Load an assembly held in memory; name is its assembly name.
Load a dotnet::Module built or edited in the script, without writing it to disk.
The names of a type's methods in a loaded assembly. On CoreCLR the list includes inherited methods such as ToString; on Mono only the type's own.
A native pointer to any static method, which is JIT-compiled first. It uses the managed calling convention, which matches the C one for primitive and pointer arguments, and takes no exception argument, so a managed exception thrown through it is unhandled.
runtime.method_pointer_from_loaded(assembly: str, type_name: str, method: str) -> Result<i64, str>Like method_pointer(), but finds the type in whichever load context actually loaded the assembly, such as a game's own. On Mono it is the same as method_pointer().
End a no-GC region started by suppress_gc(). Does nothing if there isn't one, or on Mono.
Ask for no garbage collection during the next budget bytes of managed allocation, for example while scanning pointers. Returns whether the runtime agreed; always false on Mono.
The full names of every type in a loaded assembly.
> examples
use std::io;
use std::re::dotnet::runtime;
fn main() -> Result<(), str> {
let rt = runtime::coreclr()?;
rt.load_assembly("MyLib.dll")?;
let add = rt.method_pointer("MyLib", "MyLib.Math", "Add")?;
let sum = rt.invoke(add, [2, 3])?;
io::println("2 + 3 = {}", sum);
Ok(())
}