What Is Gambas?

The Gambas 3 logo

Introduction

The master came to the pulpit,
and just as he was opening his
mouth for his daily harangue,
a nightingale started singing.
When the bird finished his song,
the master said:

"That is all I had to tell you."

Then he took his leave.

Gambas is a full-featured object language and development environment built on a BASIC interpreter.

It is released under the GNU General Public Licence.

Its architecture is largely inspired by Java. So Gambas is made up of:

  • A compiler.

  • An interpreter.

  • An archiver.

  • A scripter.

  • A development environment.

  • Many extension components.

The compiler is a fast little executable written in C:

  • It compiles about 500000 non-void lines in a second on my own Core2 Duo @2.33GHz. This speed allows a quick code/compile/test incremental development process.

  • It does almost no optimization at all at the moment, relying on the interpreter to perform this task at runtime.

  • It manages and compiles string translations by using the GNU gettext tools.

The interpreter is a small executable also written in C that is about 320 Kb on a 64 bits system.
The interpreter is a little executable also written in C that is about 508 Kb on a 64 bits system.

  • It provides all of the native features of the language, by giving indirect access to almost all the POSIX glibc features.

  • It loads classes on demand, optimizing the bytecode the first time it is run.

  • Linking between classes is done entirely at runtime. This is done as late as possible. So even large executables start quickly.

Finally, the archiver is a program that creates a Gambas executable from a Gambas project directory.

Note that a Gambas executable is just an uncompressed archive of a project. It can include any type of file, not just compiled bytecode, and it is internally accessed by the interpreter like a file system.

The Gambas Language

The main characteristics of the Gambas BASIC language are:

  • About 250 keywords and native functions to manage almost everything: arithmetic, strings, input-outputs, files, time...

  • Full error management.

  • Full process control, with pseudo-terminal management.

  • Full support for watching input-output file descriptors.

  • Event loop support with timers.

  • Native UTF-8 string support.

  • Full internationalization and translation support.

  • Ability to call external functions in system shared libraries.

But Gambas is a true object-oriented language as well. With:

  • Objects and classes.

  • Properties, methods, constants and events.

  • Public and private symbols.

  • Polymorphism, i.e. virtual method dispatching.

  • Single inheritance.

  • Constructors and destructors.

  • Array accessors, enumerators, sortable objects.

The Gambas inheritance mechanism is entirely dynamic, and allows you to:

  • Create a more specialized version of an already existing class.

  • Reimplement a class and extend it.

  • Override some methods or properties of a class.

Any classes can be inherited, reimplemented or overridden, even the native ones written in C/C++.

Finally, a native class named Observer allows you to intercept any event raised by any object.

An Extensible Language

The core Gambas interpreter is a terminal-only program. All other features are provided by components, which are groups of classes written in C/C++, or written directly in Gambas.

These components provide, among other things:

  • Graphical user interface programming, based on the QT4 toolkit, or the GTK+ toolkit.

  • Access to many database systems: MySQL, PostgreSQL, SQLite, and ODBC.

  • Network programming, with advanced protocol management: HTTP, FTP, SMTP, DNS.

  • Application automation with D-Bus.

  • SDL programming.

  • OpenGL programming.

  • XML programming.

  • CGI programming with session management.

All the Gambas features are covered by only 405 classes and 5065 symbols (at the current time). There are only a small number of concepts to learn when compared with other languages. Moreover, we tried to make the names of these symbols as coherent as possible.

All this helps to make Gambas relatively easy to learn.

Components written in C/C++ are stored in shared libraries, and components written in Gambas are just Gambas projects like any other project.

They are loaded by the interpreter at program start-up, or when needed during program execution.

Developing a component in C/C++ is a bit like developing a device driver for the Linux kernel:

  • The source code of the component is located inside the Gambas source tree.

  • The components and the interpreter communicate through an Application Programming Interface.

  • They are executed in the interpreter environment, and so cannot do whatever they want.

The documentation about writing components is not yet finished, but all the required help will be provided on the developer mailing-list.

A Scripting Language

Gambas can be used as a scripting language. This feature is provided by the scripter, a small Gambas executable that allows you to dump any Gambas code into a text file.

Here is a little script example:

#!/usr/bin/env gbs3
 
' This script returns the memory really used by the system, the cache and swap being excluded.
    
Function GetUsedMemory() As Integer
    
  Dim sRes As String
  Dim aRes As String[]
  Dim cVal As New Collection
  Dim sVal As String
    
  Exec ["cat", "/proc/meminfo"] To sRes
    
  For Each sVal In Split(sRes, "\n", "", True)
    aRes = Split(sVal, " ", "", True)
    cVal[Left$(aRes[0], -1)] = CInt(aRes[1])
  Next
    
  Return cVal!MemTotal - cVal!MemFree - cVal!Buffers - cVal!Cached + cVal!SwapTotal - cVal!SwapFree - cVal!SwapCached
    
End
    
Print Subst("Used memory: &1 Kb", GetUsedMemory())

Database, GUI & Desktop Independence

Gambas components are not just bindings. They try to abstract the underlying library they are based on, so that coherency and simplicity win.

Database Independence

With Gambas, you can write programs that are independent of the underlying database system: every database system is accessed through the same API.

For example, The database manager integrated in the IDE uses the same code to manage MySQL, PostgreSQL, SQLite or ODBC databases.

The IDE Database Manager

GUI Independence

With Gambas, you can write programs that are independent of the graphical toolkit: the QT4 component and the GTK+ component have the same interface.

Here is a Gambas example run with the QT4 and GTK+ toolkits.

The Printing example using Qt4 The Printing example using GTK+

Desktop Independence

Moreover, we tried to provide desktop independence too, by:

  • The use of icon themes according to the current desktop environment (KDE, Gnome or XFCE).

  • The gb.desktop component, based on the shell scripts from the Portland project.

Here is the Gambas IDE using KDE and Gnome icon theme.

The development environment using KDE icon theme The development environment using Gnome icon theme

The Development Environment

Gambas provides a full-featured IDE, which is itself written in Gambas.

You can create forms, insert controls just by drawing them, edit your code, and do many other things similar to other rapid application development systems.

The source code editor The debugger

The Gambas development environment provides the following features:

  • Syntax highlighting of Gambas code, HTML and CSS files.

  • Automatic completion.

  • GUI form editor.

  • Integrated debugger.

  • Icon editor.

  • String translator.

The icon editor The translation dialog

  • Subversion support.

  • Database manager.

  • Online documentation coming directly from the documentation wiki.

  • Many program examples.

Moreover, it can make installation packages for many distributions, and also tar.gz installation packages based on GNU autotools.

The following GNU/Linux distributions are supported:

  • Archlinux.

  • Debian.

  • Fedora.

  • Mandriva.

  • SuSE.

  • Slackware.

  • Ubuntu.

     

The IDE Packager

The packages made by the IDE work only if the target distribution correctly packages Gambas as specified on the How To Package Gambas page of the wiki.

We try as much as possible in lobbying distributions so that they package Gambas correctly. This is not always easy!

You can help us by submitting bug reports to the distributions that fail doing that essential task.

Finally, even though the development environment is strongly tied to the Gambas language, you don't have to use it to create Gambas programs. All Gambas tools (compiler, interpreter...) can be used from the command-line.

Download Gambas and Other Links

You can download Gambas at http://gambas.sourceforge.net from the "Download" menu.

For more information on Gambas, here are a few links:

You can report problems and bugs either on the mailing-list or on the bugtracker.

We hope that you will enjoy Gambas as much as we do! :-)

BenoƮt Minisini