[Gambas-user] Is there in Gambas a UUID implementation?

vuott at tutanota.com vuott at tutanota.com
Fri May 12 15:22:48 CEST 2023


« ...how to use Extern with the libuuid... »

I do not understand why this working example in C language:

[code C]/*
* compile:  gcc uuid.c -o uuid -luuid -Wall -g */

#include <stdlib.h>
#include <stdio.h>
#include <uuid/uuid.h>

char* uuid(char out[UUID_STR_LEN]){
  uuid_t b;
  uuid_generate(b);
  uuid_unparse_lower(b, out);
  return out;
}

int main(){
  char out[UUID_STR_LEN]={0};
  puts(uuid(out));
  return EXIT_SUCCESS;
}
[/code]

If I translate it to Gambas:
[code gambas]Library "libuuid:1.3.0"
     
    Private Const UUID_STR_LEN As Integer = 37
     
    ' void uuid_generate(uuid_t out)
    Private Extern uuid_generate(out As Integer)
     
    ' void uuid_unparse_lower(const uuid_t uu, char *out)
    Private Extern uuid_unparse_lower(uu As Integer, out As Byte[]) As Integer
     
     
    Public Sub Main()
     
      Dim uuid As New Byte[UUID_STR_LEN]
      Dim i As Integer
      
      uuid_generate(i)
      
      uuid_unparse_lower(i, uuid)
      
      Print uuid.ToString(0, 36)
     
    End
[/code]
it raises an 'unexpected error' at the first external function: "uuid_generate()".



12 mag 2023, 12:10 da mbelmonte at belmotek.net:

> El 11/5/23 a las 23:24, Martín escribió:
>
>> Is there in Gambas a UUID implementation?
>>
>
> Thanks for the answers, both of them  using uuidgen tool although shell in gambas, it works but is more efficient use this:
>
> Private Function UUID() As String
>
>   Return RTrim(File.Load("/proc/sys/kernel/random/uuid"))
>
> End
>
> Anyway if somebody know how to use Extern with the libuuid it could be even more efficient (I guest).
>
> Best regards.
>
> Martin.
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230512/1ca5f31e/attachment-0001.htm>


More information about the User mailing list