binding.d 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * D-specialized raylib functions. These functions help the D experience on
  3. * raylib.
  4. */
  5. module raylib.binding;
  6. import raylib;
  7. // stored inside raylib to validate the binding
  8. private extern(C) extern __gshared const(char)* raylibVersion;
  9. /**
  10. * Call this function before using any raylib functions to validate the binding
  11. * matches what the header information says. If you don't call this, it's
  12. * possible your binding will fail with such fun issues as memory corruption.
  13. *
  14. * If the binding is not valid, then the program will exit with a -1 error code.
  15. *
  16. * This is a template to avoid requiring linking libraylib for unittests.
  17. */
  18. void validateRaylibBinding()() @nogc nothrow {
  19. import core.stdc.stdio;
  20. import core.stdc.stdlib;
  21. import core.stdc.string;
  22. auto rlv = raylibVersion[0 .. strlen(raylibVersion)];
  23. if(rlv != RAYLIB_VERSION)
  24. {
  25. printf("FATAL ERROR: Raylib binding expected version %.*s, library version is %.*s\n",
  26. cast(int)RAYLIB_VERSION.length, RAYLIB_VERSION.ptr,
  27. cast(int)rlv.length, rlv.ptr);
  28. exit(-1);
  29. }
  30. }