Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

[D] Basic Clutter example

By: JNewt on Jun 6th, 2011  |  syntax: D  |  size: 1.04 KB  |  views: 107  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. module test2;
  2.  
  3. import std.stdio;
  4. import std.string,
  5.         std.conv,
  6.         std.c.linux.linux;
  7.  
  8. pragma(lib, "dl");
  9.  
  10. char* cstring(string s) { return cast(char*)toStringz(s); }
  11.  
  12. void main(string[] args)
  13. {
  14.  
  15.         auto lib = dlopen("libclutter-glx-1.0.so", RTLD_NOW | RTLD_GLOBAL);
  16.         T getSym(T)(string name)
  17.         {
  18.                 T ret = cast(T)dlsym(lib, cstring(name));
  19.                 assert(ret !is null);
  20.                 return ret;
  21.         }
  22.        
  23.         auto clutter_init = getSym!(int function(int*, char***))("clutter_init");
  24.         auto clutter_main = getSym!(void function())("clutter_main");
  25.     auto clutter_stage_get_default = getSym!(void* function())("clutter_stage_get_default");
  26.         auto clutter_stage_set_title = getSym!(void function(void*, char*))("clutter_stage_set_title");
  27.  
  28.         auto err = clutter_init(null, null);
  29.  
  30.         if (err != 1)
  31.                 return;         // failed to initialize
  32.  
  33.         writeln("Initialized");
  34.  
  35.         void* stage = clutter_stage_get_default();
  36.         writeln("Got default stage");
  37.  
  38.         clutter_stage_set_title(stage, cstring("A window title"));
  39.         writeln("Set title on stage");
  40.  
  41.         clutter_main();
  42.  
  43.         dlclose(lib);
  44. }