binding.d 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  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. // NOTE: should be private, but D doesn't allow private export symbols
  9. /*private*/ extern(C) extern export __gshared const(char*) raylibVersion;
  10. /**
  11. * Call this function before using any raylib functions to validate the binding
  12. * matches what the header information says. If you don't call this, it's
  13. * possible your binding will fail with such fun issues as memory corruption.
  14. *
  15. * If the binding is not valid, then the program will exit with a -1 error code.
  16. *
  17. * The function is not included when running raylib unittests, so there are no
  18. * linker errors. (raylib-d unittests do not test the C binding)
  19. */
  20. version(raylib_test) {} else
  21. void validateRaylibBinding() @nogc nothrow {
  22. import core.stdc.stdio;
  23. import core.stdc.stdlib;
  24. import core.stdc.string;
  25. auto rlv = raylibVersion[0 .. strlen(raylibVersion)];
  26. //if(rlv != RAYLIB_VERSION)
  27. if(strcmp(raylibVersion, RAYLIB_VERSION) != 0)
  28. {
  29. printf("FATAL ERROR: Raylib binding expected version %.*s, library version is %.*s\n",
  30. cast(int)RAYLIB_VERSION.length, RAYLIB_VERSION.ptr,
  31. cast(int)rlv.length, rlv.ptr);
  32. exit(-1);
  33. }
  34. }