1 module zdll; 2 /* 3 MiniM 4 5 ZDLL function interfaces 6 7 Copyright (C) Eugene Karataev 8 All rights reserved 9 10 Implementation for D - Mohow Gennady MGW 11 https://github.com/MGWL/QtE5 -- Qt-5, Forth, MiniMono, MiniM for D 12 mgw@yandex.ru 13 */ 14 15 /* max string size */ 16 const MINIM_STR_MAX = 32 * 1024; 17 18 struct _MINIM_STR { align (1): 19 union { 20 ushort len; 21 ushort type; 22 } 23 ubyte[MINIM_STR_MAX] data; 24 } 25 26 /* non-string types */ 27 const ushort MT_INT32 = 0x0000FFFF; 28 const ushort MT_INT64 = 0x0000FFFE; 29 const ushort MT_MT_DOUBLE = 0x0000FFFD; 30 31 /* return error types */ 32 const ZDLL_CALLBACK_DONE = 0; /* all done ok */ 33 const ZDLL_CALLBACK_SYNTAX = 1; /* syntax errors in parameters */ 34 const ZDLL_CALLBACK_PARAMETERS = 2; /* some parameters null */ 35 const ZDLL_CALLBACK_ARGC = 3; /* argc is more than supported */ 36 const ZDLL_CALLBACK_UNDEFINED = 4; /* undefined variable */ 37 const ZDLL_CALLBACK_ERROR = 5; /* database or process error */ 38 const ZDLL_CALLBACK_HALT = 6; /* halt command was in minimono context */ 39 40 enum WindowType { 41 Widget = 0x00000000, 42 } 43 44 extern (Windows) { 45 alias _MINIM_STR MINIM_STR; 46 47 /* callback functions */ 48 alias void function(MINIM_STR *errstr) errstr_t; 49 alias int function(MINIM_STR *str) execute_t; 50 alias int function(MINIM_STR *expr, MINIM_STR *res) eval_t; 51 alias double function(MINIM_STR *val) getdouble_t; 52 alias int function(MINIM_STR *val) getint32_t; 53 alias long function(MINIM_STR *val) getint64_t; 54 alias void function(MINIM_STR *val, MINIM_STR *str) getstr_t; 55 alias void function(double val, MINIM_STR *str) setdouble_t; 56 alias void function(int val, MINIM_STR *str) setint32_t; 57 alias void function(long val, MINIM_STR *str) setint64_t; 58 59 60 alias int function(char *name, int argc, MINIM_STR **argv, MINIM_STR *result) userfunc_t; 61 alias int function(char *name, int argc, MINIM_STR **argv) userdo_t; 62 alias int function(char *name, int argc, MINIM_STR **argv, MINIM_STR *result) readlocal_t; 63 alias int function(char *name, int argc, MINIM_STR **argv, MINIM_STR *value) writelocal_t; 64 alias int function(char *name, char *database, int argc, MINIM_STR **argv, MINIM_STR *result) readglobal_t; 65 alias int function(char *name, char *database, int argc, MINIM_STR **argv, MINIM_STR *value) writeglobal_t; 66 alias int function(char *name, int argc, MINIM_STR **argv) kill_local_t; 67 alias int function(char *name, char *database, int argc, MINIM_STR **argv) kill_global_t; 68 alias int function(int svn_test_value)set_test_t; 69 alias int function(char *name, int argc, MINIM_STR **argv, int forward, MINIM_STR *result) order_local_t; 70 alias int function(char *name, char *database, int argc, MINIM_STR **argv, int forward, MINIM_STR *result) order_global_t; 71 alias int function(char *name, int argc, MINIM_STR **argv, MINIM_STR *result) inc_local_t; 72 alias int function(char *name, char *database, int argc, MINIM_STR **argv, MINIM_STR *result) inc_global_t; 73 alias int function(char *name, int argc, MINIM_STR **argv, MINIM_STR *result) data_local_t; 74 alias int function(char *name, char *database, int argc, MINIM_STR **argv, MINIM_STR *result) data_global_t; 75 76 /* callback function list */ 77 struct _ZDLLCB { align (1): 78 errstr_t ErrStr; 79 execute_t Execute; 80 eval_t Eval; 81 getdouble_t GetDouble; 82 getint32_t GetInt32; 83 getint64_t GetInt64; 84 getstr_t GetStr; 85 setdouble_t SetDouble; 86 setint32_t SetInt32; 87 setint64_t SetInt64; 88 userfunc_t UserFunc; 89 userdo_t UserDo; 90 readlocal_t ReadLocal; 91 writelocal_t WriteLocal; 92 readglobal_t ReadGlobal; 93 writeglobal_t WriteGlobal; 94 kill_local_t KillLocal; 95 kill_global_t KillGlobal; 96 set_test_t SetTEST; 97 order_local_t OrderLocal; 98 order_global_t OrderGlobal; 99 inc_local_t IncLocal; 100 inc_global_t IncGlobal; 101 data_local_t DataLocal; 102 data_global_t DataGlobal; 103 } 104 alias _ZDLLCB ZDLLCB; 105 alias @nogc int function(ZDLLCB *cbfunc, MINIM_STR *result, int argc, MINIM_STR **argv) zdllfunc_t; 106 107 struct _ZDLLFUNC 108 { 109 align (1): 110 zdllfunc_t ZDLLFunc; 111 char *FuncName; 112 } 113 alias _ZDLLFUNC ZDLLFUNC; 114 alias @nogc ZDLLFUNC * function() zdllfuncexport_t; 115 } 116 117 118 // Read and Write buffer 119 string fromResToString(MINIM_STR* mstr) { return cast(string)mstr.data[0..mstr.len].dup; } 120 bool fromStringToExp(MINIM_STR* mstr, string exp) { 121 try { 122 ushort i; for(i = 0; i != exp.length; i++) { mstr.data[i] = exp[i]; } mstr.data[i] = 0; mstr.len = i; 123 } catch(Throwable) { 124 return false; 125 } 126 return true; 127 } 128