1 /+ dub.json:
2 {
3   "name": "d-emacs-module-test",
4   "targetType": "dynamicLibrary",
5   "dependencies": {
6     "d-emacs-module": { "path": "." }
7   }
8 }
9 +/
10 module type_conversion;
11 
12 import emacs_module;
13 
14 import core.runtime;
15 import core.stdc.stdint;
16 
17 extern (C):
18 
19 int plugin_is_GPL_compatible;
20 
21 /* Type conversion functions. */
22 
23 intmax_t intX2(EmacsEnv env, intmax_t value) { return value * 2; }
24 
25 double doubleX2(EmacsEnv env, double value) { return value * 2; }
26 
27 string stringX2(EmacsEnv env, string value) { return value ~ value; }
28 
29 bool not(EmacsEnv env, bool value) { return !value; }
30 
31 EmacsVec!intmax_t intVecX2(EmacsEnv env, EmacsVec!intmax_t value) {
32   foreach (i; 0 .. value.length) {
33     value[i] = value[i] * 2;
34   }
35   return value;
36 }
37 
38 int emacs_module_init(emacs_runtime* ert) {
39   // Validate Emacs runtime and environment.
40   EmacsRuntime runtime = {ert};
41   if (!runtime.ok) return 1;
42   EmacsEnv env = runtime.environment();
43   if (!env.ok) return 2;
44 
45   // Initialize D runtime.
46   Runtime.initialize();
47 
48   // Register functions.
49   env.defAlias!intX2("tc-int-x2", "Multiply integer by 2.");
50   env.defAlias!doubleX2("tc-double-x2", "Multiply float by 2.");
51   env.defAlias!stringX2("tc-string-x2", "Repeat string twice.");
52   env.defAlias!not("tc-not", "Returns true if value is false, vice versa.");
53   env.defAlias!intVecX2("tc-int-vec-x2", "Multiply integer vector by 2.");
54   return 0;
55 }