blob: 3efd10967e3d3ca1d44a7a72f8e4c3bee3835e6b (
plain)
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
|
using System;
using System.Reflection;
using System.Reflection.Emit;
using Crow;
using Crow.IML;
namespace HelloWorld
{
class Program {
/*static void Main (string[] args) {
using (Interface app = new Interface ()) {
app.Initialized += (sender, e) => (sender as Interface).Load ("#HelloWorld.helloworld.crow");
app.Run ();
}
}*/
public static void testMethod (Group w, Widget z) {
Console.WriteLine (w);
Console.WriteLine (z);
}
static void Main (string[] args) {
using (Interface app = new Interface ()) {
Instantiator inst = new Instantiator (app);
IMLContext ctx = new IMLContext (typeof (Widget));
ctx.EmitCreateWidget (typeof (Group));
MethodInfo mi = typeof (Program).GetMethod ("testMethod", BindingFlags.Static | BindingFlags.Public);
ctx.Emit (OpCodes.Ldloc_0);//load child on stack for parenting
ctx.il.Emit (OpCodes.Castclass, typeof (Group));
ctx.Emit (OpCodes.Dup);
ctx.EmitCreateWidget (typeof (Widget));
ctx.Emit (OpCodes.Ldloc_0);//load child on stack for parenting
ctx.il.Emit (OpCodes.Call, mi);
ctx.Emit (OpCodes.Stloc_0);
//ctx.Emit (OpCodes.Pop);
//ctx.Emit (OpCodes.Pop);
InstanciatorInvoker del = ctx.CreateDelegate (inst);
Widget w = (Widget)del (app);
Console.WriteLine ("widget ok");
}
}
}
}
|