[Gambas-user] shared librarry into gambas

Doriano Blengino doriano.blengino at ...1909...
Thu Apr 9 08:26:11 CEST 2009


M0E Lnx ha scritto:
> I always wandered myself how this works.
>
> For instance... in python, you can code something like
>
> import gtk
> import glade
> import pygtk
>   
Doing so, you are not using 'external libraries' (shared objects) - you 
are merely using a python library located somewhere in 
/usr/lib/pythonXXX which, in turn, loads a .so object tailored 
specifically for python.
> And use the methods in these modules throughout your app.
> could this be done in gambas somehow?
>   
In this respect gambas is well more powerful than python: gambas permits 
to load *any* (or almost any) external shared object using pure gambas. 
Python can not do this, if I am not wrong: it can interface only to .so 
objects written especially for that purpose.
> I have had instances in gambas where I could really use a shared
> library but i'm unable to import it... the Extern method is beyond my
> scope of skills ATM, and the documentation is sort of hard for me to
> understand.
>   
Strangely enough, this was the least problematic thing in my approach to 
gambas. The documentation is straight, even if some more examples could 
help. Simply locate the library you need, read its man page, and put the 
corresponding declaration somewhere in your source.
For example, I needed the ldap library. I wrote this:

    LIBRARY "libldap:2"

    ' to initialize the ldap client library
    PRIVATE EXTERN ldap_init(host AS String, port AS Integer) AS Pointer
    ...other necessary declarations
    ...


The declaration was taken from ldap man page, and only changed "char *" 
to "string". I had some problem with pointers, which are slightly 
"hidden" in gambas, but finally I succeded. At the end, and in a 
unexpected easy way, I had a list of records, each with variable 
attribute list, each with several values in it (a list of lists of lists).

Regards,

-- 
Doriano Blengino

"Listen twice before you speak.
This is why we have two ears, but only one mouth."





More information about the User mailing list