Why

UMAJIN “You Imagine”

The purpose of the UMAJIN script is to be a domain specific language which makes developing rich interactive applications easier and more natural. It has properties of a declarative file format and a programming language. Umajin was originally a virtual machine but has been compiled using LLVM since 2005.

The goals of the framework are

  • Fast development
  • File size conscious
  • Native internet
  • Application performance
  • Rich content (such as 3D)
  • Rich inputs (such as touch, voice, pen, depth camera)

What

This diagram describes the basic architecture of the three parts of a project. These are the creative assets, the script and the engine.

Creative Assets

The UMAJIN engine is able to load, play and render a wide range of content. Most common formats for images, audio and video are supported. There is support for fonts, 3D content, animation and Unicode text. The idea is to support the creative efforts of designers to create the most rich and interactive applications possible.

UMAJIN script

The UMAJIN script is a language for describing objects and logic. The language is designed with a low pattern syntax and object oriented features for lightweight reuse. This means that there are only a few keywords required and the syntax follows standard patterns.

For example the declare pattern is;

[keyword] [type] [name]

This pattern can be used to declare visible objects, abstract classes, properties or local variables;

  • instance image my_image
  • define image my_imageclass
  • property int my_propint = 5
  • int my_localint = 5

The language is kept simple to master with only 10 core keywords;

  • Instance
  • Define
  • If
  • Loop
  • Method
  • Raise
  • Property
  • End (ends all blocks)
  • In (for time based method calls, or assignments)
  • Tween (used for time based assignments which will be animated)

The object orientated syntax allows for very simple encapsulation of composite objects with custom methods and events. The key aim is lightweight reuse.

The base objects and composite objects built from them – support declarative programming. This is where other users (potentially using the GUI) can create functional visual programs by creating instances of your objects, setting properties and binding logic to their events.

The language is strongly typed, but allows coercion.

UMAJIN engine

This is runtime system which the language binds to. The engine supports the creation and management of visual objects and simulating, temporal assignments, animation, media and physics.

The rich object model is very important to productive development and includes items such as;

  • Image
  • Video
  • Database
  • http
  • http_server
  • Sound
  • 3D
  • Shapes
  • Text
  • Web
  • I/O
  • Timer
  • Webcam

How

The Language

Declarative programming – Objects form the skeleton of declarative programs. The programmer creates instances of the different classes of objects to form the visual basis of a document or application. The programmer can then set the properties of these objects to adjust their appearance or behaviour.

Objects can be ‘nested’ into hierarchies. For example a button can be placed inside a panel. As a result visual properties such as position and scale are inherited. When you move the panel, the child button will move with it.
Objects also have methods. Methods contain code which performs operations. Methods can also bind to events which are raised by users. For example clicking the mouse.

An important concept in this style of programming is called sub-classing. This is where a new ‘sub’ class is created from a parent class. This is also known as the new class ‘inheriting’ from its parent. This is used to create new and more complex classes from the original object model.

New programmer created classes can also have custom properties, methods and events.

Glossary

Object : A discreet bundle of components – often relating to a visual element (a button) or an abstract real world analogy (a customer). The keyword INSTANCE is used to create an instance of a class, otherwise known as an object.

Class : A class is the definition of a new type of object. The keyword DEFINE is used to create a sub-class which is based on an existing class.

Property : An attribute of an object represented by a value which has one of the UMAJIN types.

Function : An action that can be performed on this object. This is called a METHOD and will take parameters to help describe what it should do. A method contains code and can return values.

Event : A class can RAISE an event which triggers the matching named method in an instance of this class (an object).

Code : An ordered list of instructions which are performed and can modify objects and properties and call methods.

Declaring

UMAJIN script is a declarative language. This means you can literally layout the hierarchy of objects and their properties you want the engine to create for you.

Instance
Make an object of class image. This makes an actual instance of an apple.

instance image apple
   .filename=’apple.png’
end

Nested instance
Make an object of class image, make another instance inside it.

instance image apple
    .filename='apple.png'
    instance image worm
          .filename='worm.png'
    end
end

Define
Define a new sub-class of image. This does not create an actual object.

define image button
    .filename = 'button.png'
end

Define and Raise
Bind the new class to handle a mouse down event and in turn raise a custom on release event when an instance is created from this new class.

define image button
   .filename = 'button.png'
   event on_release()
   method on_mouse_down(int x, int y, int mod)
     raise .on_release()
   end
end

instance button mybutton
   method on_release()
   end
end

Logic

Logic or code is a series of instructions which each perform basic tasks which when combined together can create complex behaviours.

Types
Several basic types are available, these are simpler than full objects and include;

  • Int (int8, uint8, int16, uint16,int32, uint32, int64, uint64)
  • Real (Real32, Real64)
  • String
  • Bool
  • Vec2, vec3, Mat4
  • Color
  • Datetime
  • Var

Expressions

Programming starts with expressions and assignments. This is where a variable or property is assigned a value. The value can be an expression as simple as a single number or contain operators like addition, or calls to methods which return values.

Real velocity = 2.3			(2.3 is the expression, the = is the assignment)
Real speed = velocity * 1.87		(velocity * 1.87 is the expression)
Int length = sqrt((x1-x2)^2+(y1-y2)^2) 	(sqrt is a method inside the expression)

Conditions

Conditions are decisions where code can be branched based on the success or failure of a comparison. If, else and elseif are the structures provided. The condition needs to evaluate to non zero to be true and succeed. Comparison operators can be used to test values. These include == (equal), != (not equal), > (greater), >= (greater or equal), < (less than), <= (less than or equal). Example 1 : Simple If block

if velocity>2.1
  //place code here
end

Example 2 : If/Elseif/Else block

if velocity>2.1
  //place code here
elseif velocity==1.5
  //place code here
else
  //place code here
end

Loops

Loops allow repeating of a block of logic/code multiple times. This code will run until a condition is met. Loops can be pre AND post tested.

Example 1 : Simple pre tested loop (Loop if)

int a=0
loop a<100
   //do something many times...
   a++
end

Example 2 : Simple post tested loop (End if)

int a=0
loop 
   //do something many times...
   a++
end a>100

Arrays

Often used with loops these are a great way of processing lists of data. Umajin supports numeric and string indexes. To access the specific item in a condition, expression or assignment the index is simply specified between the square brackets.
Multi dimensional arrays can also be declared and used by having multiple sets of square brackets.

Example 1 : Declare a basic array

int my_array[]

Example 2 : Accessing an array

string my_array[]
my_array[1] = “cow”
my_array[2] = “sheep”

Example 3 : Use the array in a loop

int my_array[]
int a=0
loop a<100
   my_array[a] = rnd(100)
   a++
end

Example 4 : Declare a 2 dimensional array

string my_big_array[][]
my_array[1] [“name”]= “cow”
my_array[1] [“age”]= “13”
my_array[2] [“name”]= “sheep”
my_array[2] [“age”]= “3”

Glossary

Expression : a combination of numbers, variables, methods and operators which evaluate to a value.

Assignment : setting a property or variable to a new value (potentially from an expression)

Condition : based on a comparison succeeding or failing branch the flow of the program

Loop : repeat instructions until a condition is met

Type : Applies to the type of an object (e.g. image), or a basic variable (e.g. string, int, real)

Array : A variable which hold more than one value declared by adding square brackets []