From b51a4fac4567efedc3aaf58b9f6c183b09a31177 Mon Sep 17 00:00:00 2001 From: Paolo Molaro Date: Fri, 19 Jul 2002 17:24:56 +0000 Subject: Mono embedding sample. svn path=/trunk/mono/; revision=5938 --- samples/embed/test.cs | 11 +++++++++++ samples/embed/teste.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 samples/embed/test.cs create mode 100644 samples/embed/teste.c (limited to 'samples') diff --git a/samples/embed/test.cs b/samples/embed/test.cs new file mode 100644 index 00000000000..9e6f9228497 --- /dev/null +++ b/samples/embed/test.cs @@ -0,0 +1,11 @@ +using System; +using System.Runtime.CompilerServices; + +class Mono { + [MethodImplAttribute(MethodImplOptions.InternalCall)] + extern static string gimme(); + + static void Main() { + Console.WriteLine (gimme ()); + } +} 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 + +/* + * 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; +} + -- cgit v1.2.3