[Gambas-user] Calling library functions in Gambas2

Benoit Minisini gambas at ...1...
Thu Aug 30 02:02:33 CEST 2007


On jeudi 30 août 2007, easuter wrote:
> Thanks Ron, but I'm not sure this is working out too well, lol
>
> What I need is to use parted to get the name (eg: xfs, reiserfs or ext3) of
> the filesystem of a partition.
> I've been battling to figure out which function in libparted exactly I need
> and how to declare it (even after looking at the source code, which is
> mostly lost on me since I haven no experience with C, just a few of the
> basics).
> I think that I need ped_filesystem_type_get
> (http://www.gnu.org/software/parted/api/group__PedFileSystem.html#g7aedfb47
>2456048086ebacb6c0f03836), but have no idea how it should be declared in
> gambas to work properly.
>
> Also, I'm not sure that this feature works 100%.
>
> For example, the simplest of all I tried just to test the EXTERN functions
> in general it was:
>
> PUBLIC EXTERN printf(stest AS String, itest AS Integer) AS String IN
> "libc:6"
>
> PUBLIC SUB main()
>    PRINT printf("Testing string, now testing integer: %d", 5)
> END
>
> returns: Testing string, now testing integer: 5
>
> That worked fine. 

Not at all: printf() returns an integer, that is the number of printer 
characters.

You should have declared printf this way:

PUBLIC EXTERN printf(stest AS String, itest AS Integer) AS Integer IN "libc:6"

> However, calling the simplest function in libparted 
> (ped_get_version) did not return anything useful, but then again, I'm
> probably doing something wrong.
>
> PUBLIC EXTERN ped_get_version() AS String IN "libparted"
>
> PUBLIC SUB main()
>    PRINT ped_get_version()
> END
>
> returns an empty string.
> If I make the extern declaration use an Integer as the return data-type for
> ped_get_version, then a very useless number is returned (-1212003088).
> Same happens when made to use Pointer and if I use
> StrPtr(ped_get_version()), then the same empty string is returned as when I
> use the String datatype.
>
> I'd really appreciate any help in pointing out mistakes here, and if
> possible some indicators as to what can be done about the
> ped_filesystem_type_get function.
>
> Cheers,
>
> Eugéne

Apparently this is a bug... Try the latest revision, it should work now!

Regards,

-- 
Benoit Minisini




More information about the User mailing list