pub struct Runtime(/* private fields */);Expand description
A handle to a running .NET runtime. Cheap to clone.
Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn coreclr() -> Result<Self>
pub fn coreclr() -> Result<Self>
Starts CoreCLR with the newest installed framework, or returns the already running instance. Only one CoreCLR can run per process.
Sourcepub fn coreclr_with(options: &CoreClrOptions) -> Result<Self>
pub fn coreclr_with(options: &CoreClrOptions) -> Result<Self>
Starts CoreCLR with options. The options are ignored if it is already running.
Sourcepub fn coreclr_attach(
host_handle: *mut c_void,
domain_id: u32,
create_delegate: *const c_void,
major: u16,
) -> Result<Self>
pub fn coreclr_attach( host_handle: *mut c_void, domain_id: u32, create_delegate: *const c_void, major: u16, ) -> Result<Self>
Attaches to a CoreCLR already running in this process, for a native mod
loaded into a .NET game (e.g. Godot on CoreCLR). host_handle, domain_id
and create_delegate (coreclr_create_delegate) are captured as the
game’s runtime initialises — see the hao-godot crate; major is the
.NET major version. After this, assemblies can be loaded and methods
called as usual. Returns the existing handle if hao already has one.
pub fn backend(&self) -> Backend
Sourcepub fn attach_thread(&self)
pub fn attach_thread(&self)
Lets the calling thread run managed code. Needed for Mono on threads it didn’t start, a no-op on CoreCLR. Binding calls do this automatically.
Sourcepub fn load_assembly(&self, path: impl AsRef<Path>) -> Result<()>
pub fn load_assembly(&self, path: impl AsRef<Path>) -> Result<()>
Loads an assembly and makes it available to later loads by name.
Sourcepub fn load_assembly_bytes(&self, name: &str, bytes: &[u8]) -> Result<()>
pub fn load_assembly_bytes(&self, name: &str, bytes: &[u8]) -> Result<()>
Loads an assembly from memory. name is its assembly name.
Sourcepub fn load_module(&self, module: &Module) -> Result<()>
pub fn load_module(&self, module: &Module) -> Result<()>
Loads a module built or edited with hao, without writing it to disk.
Sourcepub fn function_pointer(
&self,
assembly: &str,
type_name: &str,
method: &str,
) -> Result<*const c_void>
pub fn function_pointer( &self, assembly: &str, type_name: &str, method: &str, ) -> Result<*const c_void>
A native pointer to the static method type_name::method in assembly.
On CoreCLR the method must be [UnmanagedCallersOnly]; for a method that
isn’t, use method_pointer instead, which calls
any method by JIT-compiling it. On Mono the returned thunk takes an extra
trailing *mut *mut c_void exception argument.
Sourcepub fn method_pointer(
&self,
assembly: &str,
type_name: &str,
method: &str,
) -> Result<*const c_void>
pub fn method_pointer( &self, assembly: &str, type_name: &str, method: &str, ) -> Result<*const c_void>
A native-callable pointer to a static method, whether or not it is
[UnmanagedCallersOnly]. The method is JIT-compiled first, so IL patched
before the assembly was loaded takes effect.
The pointer uses the managed calling convention, which matches a plain
extern "C" fn(args) -> ret for static methods with primitive and
pointer arguments. Unlike function_pointer,
it takes no trailing exception argument on either backend, so a managed
exception crosses it as an unhandled error.