Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Molaro <lupus@oddwiz.org>2002-07-19 21:24:56 +0400
committerPaolo Molaro <lupus@oddwiz.org>2002-07-19 21:24:56 +0400
commitb51a4fac4567efedc3aaf58b9f6c183b09a31177 (patch)
treefcc311f7ec96b63ce399aef6481544caf6654de7 /samples/embed
parent7d13d1ccc003828c75d8878c7a2334edc49790cb (diff)
Mono embedding sample.
svn path=/trunk/mono/; revision=5938
Diffstat (limited to 'samples/embed')
-rw-r--r--samples/embed/test.cs11
-rw-r--r--samples/embed/teste.c48
2 files changed, 59 insertions, 0 deletions
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 <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;
+}
+