Ada bindings for Raylib 5.1 library.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

64 linhas
2.2KB

  1. with Raylib; -- File path specified in 'install.sh' script.
  2. use Raylib; -- I agree with raysan5 on namespaces being boring.
  3. procedure Window is
  4. -- This is not Ada tutorial, but brief explanation of my bindings.
  5. -- This is not my usual style of programming, following conventions.
  6. --
  7. -- C uses null terminated strings, while Ada does not, hence:
  8. -- - "Foo" & Character'Val (0)
  9. -- - "Bar" & ASCII.NUL
  10. -- - To_C_String ("Baz")
  11. --
  12. -- This decision was made intentionally to avoid package body.
  13. -- If your project uses 10-40 functions and 5-10 structures:
  14. -- - Write your own bindings, it's simple and bloat-free.
  15. -- - Use someone elses Ada bindings, or run command:
  16. -- - $ gcc -c -fdump-ada-spec -C /usr/include/raylib.h
  17. --
  18. -- I don't like to use Interfaces.C package unless I have to...
  19. function To_C_String ( -- I find this better than Interfaces.C.To_C.
  20. Data : String := "" -- Concatenate this however you like...
  21. ) return String is -- Or simply use GCC generated bindings.
  22. begin
  23. return (Data & Character'Val (0)); -- This null terminates string.
  24. end To_C_String;
  25. begin
  26. Open_Window (720, 360, "Heyo Raylib!" & Character'Val (0));
  27. --
  28. -- You can have main loop in several ways, choose what you like:
  29. -- - Foo: loop ... exit when ... end loop Foo;
  30. -- - loop ... exit when ... end loop;
  31. -- - while (not) ... loop (exit when ...) ... end loop;
  32. --
  33. Main_Loop: loop
  34. exit when Window_Should_Close;
  35. --
  36. Begin_Drawing;
  37. Clear_Background (Ray_White);
  38. -- You can specify all arguments, or use defaults after one point.
  39. Draw_Text ("Heyo from Ada." & ASCII.NUL, 4, 4, 32, Black);
  40. -- You can explicitly state all arguments and their values.
  41. Draw_Text (
  42. Text => To_C_String ("Press Escape key to exit program."),
  43. X => 4,
  44. Y => 36,
  45. Size => 32,
  46. Tint => Black
  47. );
  48. -- Or at last, you can specify which arguments won't be defaults.
  49. Draw_Text (
  50. Text => To_C_String ("You can ignore some arguments."),
  51. X => 4,
  52. Y => 68
  53. );
  54. -- And naturally, you can align them however you like...
  55. End_Drawing;
  56. end loop Main_Loop;
  57. --
  58. Close_Window;
  59. end Window;