1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//! `wrapped_mono` is a safe, lightweight wrapper around the mono library. It allows embedding of the mono runtime inside a rust project. Inside this embedded runtime code written in languages supporting the .NET framework, such as C\# and F\#, can be run. This allows usage of libraries written in those languages, and using them as a scripting language. The mono runtime is used by many game engines, and this wrapper allows using it with projects written in Rust too.
//! # Safety
//! Most functions are safe and when invalid data is passed will fail in a controlled way with an error message. There are still some pitfalls, because not all errors can be caught without substantial overhead. Those errors are hard to come by, and should be always clearly
//! marked in the documentation(for example accessing an object after deleting it by deleting domain it is in), and easy to spot.
//! # Definitions of certain words used in documentation:
//!
//! **Managed Code** - code which runs in the runtime(e.g. C# code)
//!
//! **Unmanaged code** - code which runs outside runtime(in this case Rust code)
//!
//! More precise <a href = "https://docs.microsoft.com/en-us/dotnet/standard/managed-code">explanation</a>
//! ## Feature flags
//! Example
//! ```no_run
//! use wrapped_mono::*;
//! fn main(){
//! // Initialise the runtime with default version(`None`), and root domian named "main_domain"
//! let domain = jit::init("main_domain",None);
//!
//! // Load assembly "SomeAssembly.dll"
//! let assembly = domain.assembly_open("SomeAssembly.dll").expect("Could not load assembly!");
//! // Get the image, the part of assembly containing executable code(classes,methods, etc.)
//! let image = assembly.get_image();
//! // Get class named SomeClass in SomeNamespace
//! let class = Class::from_name(&image,"SomeNamespace","SomeClass").expect("Could not find SomeClass!");
//! // Create an instance of this class
//! let instance = Object::new(&domain,&class);
//! // Creating an instance of a class DOES NOT CALL ITS CONSTRUCTOR. The constructor is a method named '.ctor', that has to be called separately
//!
//! // Get a constructor method of SomeClass accepting an integer and a string (2 parameters)
//! let ctor:Method<(i32,String)> = Method::get_from_name(&class,".ctor(int,System.String)",2).expect("Could not find the constructor!");
//! // Call the constructor
//! ctor.invoke(Some(instance.clone()),(12,"SomeString".to_owned())).expect("Got an exception while calling the constructor!");
//! // Get a method "DoABackflip" form SomeClass with 1 parameter of type int returning a byte
//! let met:Method<(i32,String)> = Method::get_from_name(&class,"DoABackflip",1).expect("Could not find method \"DoABackFlip\"!");
//! // Call "DoABackflip" method on an instance
//! let res_obj = met.invoke(Some(instance),(32,"Message".to_owned())).expect("Got an exception while calling DoABackflip!").expect("Got null from DoABackFlip");
//! // Unbox the result to get a raw integer from a boxed integer
//! let res = res_obj.unbox::<u8>();
//! // Create a function with the special "invokable" attribute
//! #[invokable]
//! fn sqrt(input:f32)->f32{
//! if input < 0.0{
//! // can't get sqrt of a negative number, so create a managed exception and throw it.
//! unsafe{Exception::arithmetic().raise()};
//! }
//! input.sqrt()
//! }
//! // Replace a method with "[MethodImplAttribute(MethodImplOptions.InternalCall)]" atribute with a rust function
//! add_internal_call!("SomeClass::SqrtInternalCall",sqrt);
//! // This supports all types with `InteropRecive` trait
//! #[invokable]
//! fn avg(input:Array<Dim1D,f32>)->f32{
//! let mut avg = 0.0;
//! for i in 0..input.len(){
//! let curr = input.get([i]);// get the element at index i
//! avg += curr/(input.len() as f32);
//! }
//! avg
//! }
//! // Replace a method with "[MethodImplAttribute(MethodImplOptions.InternalCall)]" attribute with a rust function
//! add_internal_call!("SomeClass::AvgInternalCall",sqrt);
//!}
//! ```
pub use *;
/// Utilities related to managed arrays.
/// Functions and types related to `MonoAssembly` type.
/// Autognerated, unsafe binds to mono library
/// Representation of managed classes and utilities related to them.
/// Safe representation of a delegate.
// pub mod delegate;
/// Functions and types related to `MonoDomain` type.
///Utilities related to Exceptions.
/// Functions related to garbage collection.
/// Part of assembly holding the executable code.
/// Traits related to passing data between managed and unmanaged classes.
/// Functions related to Mono JIT Runtime
/// Utilities related to metadata. Bare bones and experimental.
/// Safe representation of Methods(functions) form managed code an utilities related to managing and calling them.
/// Managed string utilities.
/// Utilities related to managed objects.
/// Experimental Profiler API. Bare bones and may contain bugs.
/// Safe representation of the `System.Type` type.
///Functions related to getting data about and configuring mono runtime.
// Some utility traits used internally.
pub use Array;
pub use Assembly;
pub use ;
// pub use delegate::{Delegate, DelegateTrait};
pub use Domain;
pub use Exception;
pub use Image;
pub use ;
pub use Method;
pub use MString;
pub use ;
pub use ReflectionType;
/// Custom macros used by `wrapped_mono`
pub use wrapped_mono_macros; // Custom macros
pub use ;
static STR2CSTR_ERR: &str = "Cold not create CString!";
static CSTR2STR_ERR: &str = "Could not convert CString to String";
pub static TEST_DOMAIN: LazyLock =
new;