binding.d 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  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. * The function is not included when running raylib unittests, so there are no
  17. * linker errors. (raylib-d unittests do not test the C binding)
  18. */
  19. version(raylib_test) {} else
  20. void validateRaylibBinding() @nogc nothrow {
  21. import core.stdc.stdio;
  22. import core.stdc.stdlib;
  23. import core.stdc.string;
  24. auto rlv = raylibVersion[0 .. strlen(raylibVersion)];
  25. if(rlv != RAYLIB_VERSION)
  26. {
  27. printf("FATAL ERROR: Raylib binding expected version %.*s, library version is %.*s\n",
  28. cast(int)RAYLIB_VERSION.length, RAYLIB_VERSION.ptr,
  29. cast(int)rlv.length, rlv.ptr);
  30. exit(-1);
  31. }
  32. }