Language Buindings

Python
Perl
PHP
Java
Matlab

OSCATS is written in object-oriented C using the Glib GObject framework. The choice of C and GObject was strategic, perhaps more than practical: Compiled C code is fast, and there are automatic bindings generators for GObject-based libraries for a variety of different languages due to the popularity of GTK. Many CAT programmers may not be familiar with C or may prefer higher-level langauges (there is certainly something to be said for automatic garbage collection!), so OSCATS comes with bindings to several popular languages. Since the semantics and most of the names are the same across languages, the C API serves as the definitive reference for OSCATS. This chapter discusses the particular naming convention for each language, along with any other language-specific peculiarities. For further information, see the example programs provided with OSCATS, which produce in parallel the same simulations in each language.

Python

The gobject module must be imported before the oscats module in order to resolve dynamic linking dependencies. Since Python has automatic garbage collection, it isn't necessary to free objects explicitly.

Python class names have been stripped of the package name. So, GGslVector becomes oscats.GslVector and OscatsTest becomes oscats.Test. Python method names have been stripped of the package and class name. So, g_gsl_vector_get(obj, i) becomes obj.get(i) and oscats_test_administer(tst, ex) becomes tst.administer(ex). Functions that are not object methods retain their full C names, for example oscats.oscats_rnd_normal(1).

Objects with an explicit construction method, oscats_*_new(...), can be created with the usual Python symantics. For example,

v = oscats.GslVector(10)

Objects without a *_new() function or that require construction properties can be created with the generic gobject.new() function. Construction properties are supplied as keyword arguments. For example,

model = gobject.new(oscats.ContModelL1p)
tst = gobject.new(oscats.Test, id=name, itembank=bank)