iMSB Lua Widget Library

Introduction

With the iMSB Lua Widget scripting libraries user specific widgets can be programmed and attached to an iMSB display view. Widgets are essentially a graphic representation of a display element, such as a meter, used to display sensor values or any other graphic representation. A Lua Widget is attached to a display view the same way as any other pre-defined meter.

Lua Widgets are programmed using the lua scripting language. Lua is a powerful, efficient and embeddable multi-paradigm programming language designed as a scripting language. Detailed description and reference information is available at  www.lua.org.

The Lua Widget library implements a subset of the iOS UIKit objects and functions. Basic display elements are taken from UIView, UILabel and UIImage. More advanced and efficient display elements taken from CAShapeLayer and CGPath are available. Most of these objects can be animated, in order to develop complex and rich display elements. Programmers having a knowledge of the Apple’s UIKit will immediately feel at home. It is however recommended that the user reads through the apple documentation before starting using the library.

Lua Widget scripts can be used together with the Lua Sensor scripting library, to access sensor values and other attributes that need to be displayed in a Widget. It is important to note that the widget library solely handles graphic representations and animations. It does not provide any means to access sensor data. Useful sensor and value data need to be accessed via the sensor library.

In order to use Lua scripts the “Expert mode” must be enabled in the “Data logging” section of the application preferences.

iMSB Lua Widget library reference

The Lua Widget Scritping Library provides the following classes as an extension to the language:

  • Widget class: The class represents the canvas of the widget that is allocated in the display view. All drawing is performed in the widget and constrained to its bounds.
  • Box class: Box are the fundamental building blocks of your Widget, and the Box class defines the behaviors that are common to all its subclasses. The Box class represents a rectangular zone that can be sized, moved, have a background and border color. It renders content within its bounds rectangle. In addition some interaction with the object can be performed. Box can nest inside other boxes to create view hierarchies, which offer a convenient way to organize related content.
  • Label class: A Label is a display object that displays one of informational text. You can configure the overall appearance of a label's text, such as the font, its color and text alignment. In addition some predefined animation functions are provided for you. The Label class inherits from the Box class. Thus all functions defined for the Box class also apply to a Label object.
  • Image class: The Image let you efficiently draw any image that can be specified using an image file stored on the iCloud or on the device. An image content can be changed dynamically and at any time during the script execution. In the current implementation only PNG images can be displayed. The Image class inherits from the Box class. Thus all functions defined for the Box class also apply to a Label object.
  • Layer class: Layer objects are 2D surfaces organized in a 3D space and are at the heart of everything you do when performing complex animations or drawing. Like Box (and its subclasses), layers manage information about the geometry, content, and visual attributes of their surfaces. When performing animations you should always consider doing so with a Layer object instead of a Box, as system resources are handled much more efficiently.A Layer allows to draw complex drawing shapes with cubic Bezier splines. This is performed by defining a so called path that will be rendered at runtime. A path specifies a set of graphic primitives, such as lines, arcs, ellipses, etc. you use to construct your drawing. Each of these drawing primitives creates a subpath within a path. Attributes of you drawing such as line color, style, background colors, etc. may as well be specified. Constructing a path must be done within an :beginPath and :applyPath call in your code in order for the system to know which primitives belong to the path you wish to draw. Unlike other objects a path does not have an implicit animation. The path within a Layer may however be as well animated using a concrete animation function.

iMSB Lua Widget Library reference

Get the iMSB Lua Sensor Scripting Library refenrence documentation. 

Sample scripts

You can refer to this sample script to help you get started with iMSB Lua.

 Thomas Styger, iMSB   © 2012