O'Reilly logo

Erlang Programming by Francesco Cesarini, Simon Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

wxErlang: An Erlang Binding for wxWidgets

In binding wxWidgets to Erlang, it is necessary to decide how to render its object-oriented structure and event-handling mechanism within Erlang so that it fits as closely as possible with the design principles underlying the language. This section explains the top-level correspondences, with more specific details coming in subsequent sections.

The wxErlang documentation contains an overview page together with an EDoc page for each module, which gives type information on each function as well as linking into the corresponding pages of the wxWidgets online documentation.

Objects and Types

In the wxErlang binding, each class is represented by a module and each object by an object reference. For example, the wxErlang function call in:

File = wxMenu:new(),

constructs a new wxMenu object and assigns a reference to this object to the File variable, with the same effect as the call to the constructor in the C++ fragment:

wxMenu *File = new wxMenu;

To call methods on the object, as in this C++ example:

File->Append(NEW,wxT("New\tCtrl-N"));

wxErlang provides a three-argument append function, where the first argument to append is the object reference, File:

wxMenu:append(File,?NEW,"New\tCtrl-N"),

The pattern of wxErlang functions taking an extra “this” or “self” value as the first argument is used throughout the binding. In a similar way, the constructors for a class are replaced by new functions of the same arity. Some wxWidgets methods take optional arguments; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required