Advertisement
SimonWright

glfwGetRequiredInstanceExtensions binding demo

Mar 27th, 2022
2,954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 1.42 KB | None | 0 0
  1. // hdr.h
  2. char **strings(int *count);
  3.  
  4. // bdy.c
  5. #include "hdr.h"
  6.  
  7. char *data[] = {"now", "is", "the", "time"};
  8.  
  9. char **strings(int *count) {
  10.   *count = sizeof(data) / sizeof(char*);
  11.   return data;
  12. }
  13.  
  14. --  caller.adb
  15. with Ada.Text_IO;
  16. with Ada.Unchecked_Conversion;
  17. with Interfaces.C.Strings;
  18. with System;
  19.  
  20. procedure Caller is
  21.    function Strings return Interfaces.C.Strings.chars_ptr_array;
  22.    function Strings return Interfaces.C.Strings.chars_ptr_array is
  23.       function Inner (Count : out Interfaces.C.int) return System.Address
  24.       with
  25.         Import,
  26.         Convention => C,
  27.         External_Name => "strings";
  28.       Count : aliased Interfaces.C.int;
  29.       Address : System.Address;
  30.    begin
  31.       Address := Inner (Count);
  32.       declare
  33.          subtype Result_Type
  34.            is Interfaces.C.Strings.chars_ptr_array
  35.              (1 .. Interfaces.C.size_t (Count));
  36.          type Result_Type_P is access Result_Type;
  37.          function Convert is new Ada.Unchecked_Conversion (System.Address,
  38.                                                            Result_Type_P);
  39.       begin
  40.          return Result : Result_Type do
  41.             Result := Convert (Address).all;
  42.          end return;
  43.       end;
  44.    end Strings;
  45.    Answer : Interfaces.C.Strings.chars_ptr_array := Strings;
  46. begin
  47.    for Str of Strings loop
  48.       Ada.Text_IO.Put_Line (Interfaces.C.Strings.Value (Str));
  49.    end loop;
  50. end Caller;
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement