diff options
Diffstat (limited to 'samples/embed/teste.c')
-rw-r--r-- | samples/embed/teste.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/samples/embed/teste.c b/samples/embed/teste.c new file mode 100644 index 00000000000..4727c51a736 --- /dev/null +++ b/samples/embed/teste.c @@ -0,0 +1,48 @@ +#include <mono/jit/jit.h> + +/* + * Very simple mono embedding example. + * Compile with: + * gcc -o teste teste.c `pkg-config --cflags --libs mono` + * mcs test.exe + * Run with: + * ./teste test.exe + */ + +static MonoString* +gimme () { + return mono_string_new (mono_domain_get (), "All your monos are belong to us!"); +} + +int +main(int argc, char* argv[]) { + MonoDomain *domain; + MonoAssembly *assembly; + const char *file; + int retval; + + if (argc < 2) + return 1; + file = argv [1]; + /* + * mono_jit_init() creates a domain: each assembly is + * loaded and run in a MonoDomain. + */ + domain = mono_jit_init (file); + /* + * We add our special internal call, so that C# code + * can call us back. + */ + mono_add_internal_call ("Mono::gimme", gimme); + assembly = mono_domain_assembly_open (domain, file); + if (!assembly) + return 2; + /* + * mono_jit_exec() will run the Main() method in the assembly + * and return the value. + */ + retval = mono_jit_exec (domain, assembly, argc - 1, argv + 1); + mono_jit_cleanup (domain); + return retval; +} + |