1 module testdll; 2 3 // the names are prefixed with `test_dll` so as to not clash in python 4 5 string testdll_foo() { 6 return "20 Monkey"; 7 } 8 9 // this won't get wrapped 10 string testdll_foo(int i) { 11 import std.conv: text; 12 return text(i); 13 } 14 15 string testdll_bar(int i) { 16 if (i > 10) { 17 return "It's greater than 10!"; 18 } else { 19 return "It's less than 10!"; 20 } 21 } 22 23 24 auto testdll_baz(int i = 10, string s = "moo") { 25 import std.typecons: tuple; 26 return tuple(i, s); 27 } 28 29 30 class TestDllFoo { 31 int m_i; 32 this() { } 33 this(int i) { 34 m_i = i; 35 } 36 this(int i, int j) { 37 m_i = i + j; 38 } 39 string foo() { 40 import std.format: format; 41 return format("Foo.foo(): i = %s", m_i); 42 } 43 int length() { return 10; } 44 int opSlice(long i1, long i2) { 45 return 12; 46 } 47 int opIndex(int x, int y) { 48 return x + y; 49 } 50 TestDllFoo opBinary(string op)(TestDllFoo f) if(op == "+") 51 { 52 return new TestDllFoo(m_i + f.m_i); 53 } 54 55 struct Range { 56 int i = 0; 57 58 @property bool empty() { 59 return i >= 10; 60 } 61 @property int front() { 62 return i+1; 63 } 64 void popFront() { 65 i++; 66 } 67 } 68 69 Range opSlice() { 70 return Range(); 71 } 72 @property int i() { return m_i; } 73 @property void i(int j) { m_i = j; } 74 void a() {} 75 void b() {} 76 void c() {} 77 void d() {} 78 void e() {} 79 void f() {} 80 void g() {} 81 void h() {} 82 void j() {} 83 void k() {} 84 void l() {} 85 void m() {} 86 void n() {} 87 void o() {} 88 void p() {} 89 void q() {} 90 void r() {} 91 void s() {} 92 void t() {} 93 void u() {} 94 void v() {} 95 void w() {} 96 void x() {} 97 void y() {} 98 void z() {} 99 100 override string toString() { 101 import std.conv: text; 102 return text("TestDllFoo(", m_i, ")"); 103 } 104 } 105 106 string delegate() dg_ret() { 107 return { return "returning a delegate works"; }; 108 } 109 110 string dg_arg(string delegate(string arg) dg) { 111 assert(dg !is null, "dg_arg: delegate cannot be null"); 112 return dg("foo"); 113 } 114 115 class TestDllBar { 116 int[] m_a; 117 this() { } 118 this(int[] i ...) { m_a = i; } 119 } 120 121 struct TestDllStruct { 122 int i; 123 char[] s; 124 } 125 126 TestDllFoo testdll_spam(TestDllFoo f) { 127 f.foo(); 128 auto g = new TestDllFoo(f.i + 10); 129 return g; 130 } 131 132 void testdll_throws() { 133 throw new Exception("Yay! An exception!"); 134 }