[Gambas-user] How to make Class file to Library for use in other Gambas applications

Willy Raets willy at ...2734...
Wed Feb 22 01:03:35 CET 2012


Hi all,

I've been searching and reading my butt of on how to make a library with
Gambas 2 for Gambas 2.

It is a very simple and short library so I can get familiar with how it
works and do a how to documentation so others can benefit of my learning
curve as well and you will be bored less with questions like this on
this list (hopefully).

I have a simple Class called SysInfo (made it Start up Class)
That is all the project contains, no forms or modules.

------ Code for Class SysInfo ---

PUBLIC OS AS String
PUBLIC Kernel AS String
PUBLIC KernelRelease AS String 
PUBLIC KernelVersion AS String 
PUBLIC Architecture AS String 

PUBLIC SUB ReadInfo()

  DIM sLineOSYS, sLineKERN, sLineKERNR, sLineKERNV, sLineARCH AS String
  '--- Read system information ---
  EXEC ["uname", "-o"] TO sLineOSYS
  EXEC ["uname", "-s"] TO sLineKERN
  EXEC ["uname", "-r"] TO sLineKERNR
  EXEC ["uname", "-v"] TO sLineKERNV
  EXEC ["arch"] TO sLineARCH
  OS = Trim(sLineOSYS)
  Kernel = Trim(sLineKERN)
  KernelRelease = Trim(sLineKERNR)
  KernelVersion = Trim(sLineKERNV)
  Architecture = Trim(sLineARCH)

END

----- End Code Class file -----

Now I read somewhere you need to make a gambas executable and place it
in the project folder of the project you want to use it.

So I made an executable named it SysInfo.gambas
Placed it in the project folder of a project where I need the library
and then I get stuck.

How to I use the library in my code?

Gambas documentation goes into C libraries but says nothing about gambas
libraries.
Does it work the same for Gambas libraries, because I have tried with
using LIBRARY "SysInfo.gambas" and I am not getting there.
And if I would do EXTERN ReadInfo() compiler gives no problem.
But how to get the OS because EXTERN OS is not okay for the compiler.

I was expecting, because of the library being Gambas for Gambas that it
would be eazier. Like that the compiler would recognize SysInfo and that
a simple SysInfo.ReadInfo would run the getting of the info and a simple
SysInfo.OS would give me the OS info.
But obviousily it ain't that simple.

How do I get my application to recognize SysInfo?
And next, how do I use SysInfo in my application

I am missing some information there? 
Any links to some good example maybe that could get me on the road again
or some hints?

Thanks,

Willy





More information about the User mailing list