1 module janet; 2 3 public import janet.d; 4 5 public import janet.c : Janet,JanetFunction,JanetTable,JanetKV; 6 7 JanetTable* coreEnv; /// The core environment 8 9 version(JanetD_NoAutoInit) // Sometimes we might not want to start up a janet instance on every thread's creation 10 { 11 /** 12 Initialize Janet. This is done automatically if not compiled with the JanetD_NoAutoInit 13 version, at the initialization of every thread. Compiling with the JanetD_NoAutoInit, 14 these functions must be used instead, which do all the same stuff that is normally done 15 automatically. 16 */ 17 void initJanet() 18 { 19 janet_init(); 20 coreEnv = janet_core_env(null); 21 } 22 alias deinitJanet = janet_deinit; /// ditto 23 } 24 else 25 { 26 static this() 27 { 28 janet_init(); 29 coreEnv = janet_core_env(null); 30 } 31 static ~this() 32 { 33 janet_deinit(); 34 } 35 } 36 37 import janet.c; 38 39 /// An enum of the different kinds of things you can turn a string into. 40 enum JanetStrType 41 { 42 STRING, 43 SYMBOL, 44 KEYWORD 45 } 46 47 /** 48 Define an immutable value in Janet, as Janet's "def". 49 Immutable means something slightly different in Janet than in D, 50 so this doesn't take in a const or immutable value. 51 Name and documentation should be string literals, or otherwise 52 made to be zero-terminated outside of this. 53 */ 54 @nogc void janetDef(T)(JanetTable* env,immutable(char)* name,T val,immutable(char)* documentation = "") 55 { 56 import janet.c : janet_def; 57 janet_def(env,name,janetWrap(val),documentation); 58 } 59 60 /** 61 As janetDef, but value is mutable, as Janet's "var". 62 */ 63 @nogc void janetVar(T)(JanetTable* env,immutable(char)* name,T val,immutable(char)* documentation = "") 64 { 65 import janet.c : janet_var; 66 janet_var(env,name,janetWrap(val),documentation); 67 } 68 69 /** 70 Gets a Janet value from a JanetTable. Can take any Janet-compatible type as a key. 71 */ 72 @nogc Janet get(T)(JanetTable* tbl,T key) 73 { 74 return janet_table_get(tbl,janetWrap(key)); 75 } 76 /// As above, but for a struct (JanetKV*). 77 @nogc Janet get(T)(JanetKV* tbl,T key) 78 { 79 return janet_struct_get(tbl,janetWrap(key)); 80 } 81 82 package struct JanetAbstractClassHelper(T) 83 { 84 T obj; 85 }