SHARE
TWEET

Untitled

a guest Feb 1st, 2012 127 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module dk.tcl;
  2.  
  3. struct TclProcs
  4. {
  5. __gshared extern(C):
  6.     void function(const char* argv0) Tcl_FindExecutable;
  7.     const(char*) function() Tcl_GetNameOfExecutable;
  8.     int function(Tcl_Interp* interp, char* str) Tcl_Eval;
  9.     Tcl_Interp* function() Tcl_CreateInterp;
  10.     char* function(Tcl_Obj * objPtr, int* lengthPtr) Tcl_GetStringFromObj;
  11.     char* function(const Tcl_Obj * objPtr) Tcl_GetString;
  12.     void function(Tcl_Interp* interp, char* str, Tcl_FreeProc* freeProc) Tcl_SetResult;
  13.     Tcl_Command function(Tcl_Interp* interp, char* cmdName,
  14.                          Tcl_ObjCmdProc proc, ClientData clientData,
  15.                          Tcl_CmdDeleteProc deleteProc) Tcl_CreateObjCommand;
  16.    
  17.     int function(Tcl_Interp* interp) Tcl_Init;
  18.     void function(Tcl_Interp* interp) Tcl_DeleteInterp;
  19. }
  20.  
  21. struct TkProcs
  22. {
  23. __gshared extern(C):
  24.     int function(Tcl_Interp* interp) Tk_Init;
  25.     Tk_Window function(Tcl_Interp* interp) Tk_MainWindow;
  26.     void function() Tk_MainLoop;
  27. }
  28.  
  29. string getAliasesAsString(T, string TString)()
  30. {
  31.     string result;
  32.     foreach (string member; __traits(allMembers, T))
  33.     {
  34.         result ~= "alias " ~ TString ~ "." ~ member ~ " " ~ member ~ ";\n";
  35.     }
  36.     return result;
  37. }
  38.  
  39. // mixin to local scope
  40. mixin(getAliasesAsString!(TkProcs, "TkProcs"));
  41. mixin(getAliasesAsString!(TclProcs, "TclProcs"));
  42.  
  43. version (Windows)
  44. {
  45.     // Safe symbol loader. Pass a DLL handle, the exported function name,
  46.     // and a static field at CT. The function will throw if the symbol name is not found.
  47.     private void loadSymbol(alias field)(HANDLE handle, string symbol)
  48.     {
  49.         field = cast(typeof(field))enforce(GetProcAddress(handle, symbol.toStringz),
  50.                                            format("%s failed to load.", symbol));
  51.     }
  52.  
  53.     shared static this()
  54.     {
  55.         HMODULE hTcl = enforce(LoadLibraryA("tcl85.dll"));
  56.         foreach (string member; __traits(allMembers, TclProcs))
  57.         {
  58.             mixin("loadSymbol!(" ~ "TclProcs." ~ member ~ ")(hTcl, member);");
  59.         }
  60.  
  61.         HMODULE hTk = enforce(LoadLibraryA("tk85.dll"));
  62.         foreach (string member; __traits(allMembers, TkProcs))
  63.         {
  64.             mixin("loadSymbol!(" ~ "TkProcs." ~ member ~ ")(hTk, member);");
  65.         }
  66.     }
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top