1 module plugin; 2 3 /** 4 * Plugins must be made for a post-task for presets on generate.d 5 * I don't still have much experience on how should I do it, but following a pattern will 6 * really help at those things 7 */ 8 abstract class Plugin 9 { 10 private import std.stdio:writeln; 11 /** 12 * If it returned from main, the plugin should be processed 13 */ 14 static int SUCCESS = 1; 15 /** 16 * Should not process plugin 17 */ 18 static int ERROR = 0; 19 /** 20 * Target for getting the options inside bindbc-generate 21 */ 22 abstract string target() 23 out(r) 24 { 25 if(r == "") 26 writeln("FATAL ERROR:\n\n\nPlugin target can't be null\n"); 27 // assert(r != "", "FATAL ERROR:\n\n\nPlugin target can't be null\n"); 28 } 29 /** 30 * Gets the error reason 31 */ 32 final int returnError(string err) 33 { 34 if(err.length <= 20) 35 writeln("Please provide better error messages for easier debugging"); 36 error = err; 37 return Plugin.ERROR; 38 } 39 /** 40 * Wether convertToD_Pipe can be called 41 */ 42 abstract int main(string[] args) 43 out(r) 44 { 45 if(r != Plugin.SUCCESS && r != Plugin.ERROR) 46 writeln("Please, use Plugin.SUCCESS or Plugin.ERROR as your return value"); 47 } 48 /** 49 * Executed after main, this is the string to be processed/convert to D style declaration 50 */ 51 abstract string convertToD_Pipe(); 52 53 /** 54 * Executed after generate processing 55 */ 56 abstract int onReturnControl(string processedStr); 57 58 /** 59 * Provides help information when every dll is loaded but no argument was passed 60 */ 61 abstract string getHelpInformation() 62 out(r) 63 { 64 if(r == "") 65 writeln("Please provide help information"); 66 else if(r.length <= 50) 67 writeln("Help information about plugin is essential\n 68 Think if you could elaborate it a bit more!"); 69 } 70 71 /** 72 * Internal use only, setting up this member yourself will have no effect 73 */ 74 public bool hasFinishedExecution; 75 /** 76 * Internal use only 77 */ 78 public bool willConvertToD; 79 /** 80 * Set it directly before returning or use returnError function 81 */ 82 public string error; 83 } 84 85 mixin template PluginLoad() 86 { 87 import core.sys.windows.dll:SimpleDllMain; 88 mixin SimpleDllMain; 89 }