Difference between revisions of "Reggae tutorial: Accessing Reggae in applications"

From MorphOS Library

(Opening and closing multimedia.class)
(Opening and closing multimedia.class)
Line 20: Line 20:
 
'''Note:''' Some programmers use automatic library opening and closing by linking with ''libauto''. ''multimedia.class'' can be added to the list of automatically opened libraries, but it is not added by default.
 
'''Note:''' Some programmers use automatic library opening and closing by linking with ''libauto''. ''multimedia.class'' can be added to the list of automatically opened libraries, but it is not added by default.
  
A complete [http://krashan.ppa.pl/reggae/files/tutorial_basic.c example code] shows Reggae initialization. The example opens ''multimedia.class'' and, if it succeeded, prints the version and revision of multimedia.class to the console.
+
A complete [http://krashan.ppa.pl/reggae/files/tutorial_basic.c example code] shows Reggae initialization. The example opens ''multimedia.class'' and, if it succeeded, prints the version and revision of ''multimedia.class'' to the console.
  
 
==I don't like C/C++, what now?==
 
==I don't like C/C++, what now?==
  
 
Reggae can be used from any programming language. It has to fulfill some minimal set of features however. The first one is ability to call functions from standard MorphOS shared libraries, ''intuition.library'' and ''exec.library'' at least. Then ability to call functions from ''multimedia.class''. Many programming languages used on MorphOS have tools for creating bindings (or stubs, or whatever it is called) to shared libraries, based on C headers and *.fd files. Creating bindings for ''multimedia.class'' should not be difficult then. Then the language must have ''DoMethod()'' call. For C/C++ this call is provided by ''libabox'', a static library. Another important feature is ability to handle tag-based functions in some sane way. Taglist can be always built by hand, but passing tags as arguments to variable args functions is convenient.
 
Reggae can be used from any programming language. It has to fulfill some minimal set of features however. The first one is ability to call functions from standard MorphOS shared libraries, ''intuition.library'' and ''exec.library'' at least. Then ability to call functions from ''multimedia.class''. Many programming languages used on MorphOS have tools for creating bindings (or stubs, or whatever it is called) to shared libraries, based on C headers and *.fd files. Creating bindings for ''multimedia.class'' should not be difficult then. Then the language must have ''DoMethod()'' call. For C/C++ this call is provided by ''libabox'', a static library. Another important feature is ability to handle tag-based functions in some sane way. Taglist can be always built by hand, but passing tags as arguments to variable args functions is convenient.

Revision as of 13:15, 26 January 2010

Reggae is operated from application with two APIs. One of them is generic object oriented BOOPSI API with its DoMethod(), GetAttr(), SetAttrs() etc. The second API is just a shared MorphOS library one, provided by multimedia.class and is, of course, Reggae specific. To use Reggae one must open multimedia.class as every shared library. For BOOPSI API intuition.library must be opened, which almost all programs do anyway.

Opening and closing multimedia.class

The first step is to add needed includes:


#include <proto/multimedia.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <clib/alib_protos.h>


The first file contains definition of multimedia.class library API. It also includes <classes/multimedia/multimedia.h>, containing Reggae structures, constants, tags and macros. The rest of includes are not Reggae specific, in fact most projects include them anyway, as they define basic system services. There are also additional Reggae headers, their including depends on application and will be covered in further tutorials.

Now we are ready for Reggae initialization. All what has to be done is opening multimedia.class just like an ordinary MorphOS shared library. The only noticeable difference is that library name contains path part, as Reggae classes are not directly on library search path:


struct Library* MultimediaBase;

if (MultimediaBase = OpenLibrary("multimedia/multimedia.class", 52))
{
  /* Now Reggae is ready to use until the library is closed. */
  CloseLibrary(MultimediaBase);
}


As with every library, the name of the base is important, as it is implicitly used in all calls to the library API as a hidden parameter. Note also the usual error handling, multimedia.class is disk-based and also performs some disk activity at startup, then checking the library base against NULL is recommended. 52 is the current multimedia.class version. Applications should request this version, as previous ones have some important features missing. Reggae cleanup is done with classic CloseLibrary() call.

Note: Some programmers use automatic library opening and closing by linking with libauto. multimedia.class can be added to the list of automatically opened libraries, but it is not added by default.

A complete example code shows Reggae initialization. The example opens multimedia.class and, if it succeeded, prints the version and revision of multimedia.class to the console.

I don't like C/C++, what now?

Reggae can be used from any programming language. It has to fulfill some minimal set of features however. The first one is ability to call functions from standard MorphOS shared libraries, intuition.library and exec.library at least. Then ability to call functions from multimedia.class. Many programming languages used on MorphOS have tools for creating bindings (or stubs, or whatever it is called) to shared libraries, based on C headers and *.fd files. Creating bindings for multimedia.class should not be difficult then. Then the language must have DoMethod() call. For C/C++ this call is provided by libabox, a static library. Another important feature is ability to handle tag-based functions in some sane way. Taglist can be always built by hand, but passing tags as arguments to variable args functions is convenient.