Libraries - Create Type

Implemented as of Version2015.r1

A Type Library is a static memory object with functions in the form of a library. It adds a new structure data type. A Type Library (Type object) is similar to a structure in Luna, which provide additional functions and can also be used in expressions.

The Type object can therefore make according to design appropriate functions that can be applied to the object. Each object has its own local and static memory. Therefore Type objects are similar to dimensioned variables (local/temporary or global).

In contrast to an interface or module, no nested syntax can be defined by keywords in an object. The syntax is derived from the functionality of the object and may additionally implemented further objects and their functions.

In a Type object there is only a root-level in which the actual functions (methods) are intended for use by the Luna developers.

In the folder Constructors you find the optional usable object-handlers (basis functions), they can have each object for initialize, assign or embedding in expressions. For type objects it is possible to have no handlers. In this case the compiler will automatically use the default Constructor/Destructor for type objects.*

For the use of the object in expressions with operators - eg. „+“, „-“, „and“, the function „operator overloading“ is supported. This optional handlers (basis functions) for operators allows you, for example, an Addition with two different objects.

See also example library xstring.object in folder /Library/Example/ . The example library is stocked with corresponding descriptions. When creating e.g. a method or constructor, a short explanation is automatically available as comment.

Code-Example:
uint64-example.luna
#library "Library/Example/uint64.type"
 
avr.device = atmega328p
avr.clock = 20000000
avr.stack = 96
 
uart.baud = 19200			' Baudrate
uart.recv.enable			' Senden aktivieren
uart.send.enable			' Empfangen aktivieren
 
dim value as word
dim a,b,r as uint64
 
print 12
 
a = 0x30303030
 
a = new uint64(0x30303030,0x30303030)
b = new uint64(0x31313131,0x31313131)
 
'print the values of the objects using the object's functions
print "value of a = 0x";hex(a.long2);hex(a.long1)
print "value of b = 0x";hex(b.long2);hex(b.long1)
 
'math operation with this objects
print "math operation 'r = a + b + new uint64(0x32323232,0x32323232)'"
r = a + b + new uint64(0x32323232,0x32323232)
print "result: r = 0x";hex(r.long2);hex(r.long1);" - expected: 0x9393939393939393"
 
print "call method 'test1(r,a,b)'"
test1(r,a,b)
print "result: r = 0x";hex(r.long2);hex(r.long1);" - expected: 0x6161616161616161"
 
halt()
 
 
'argument test
procedure test1(byRef r as uint64, byRef a as uint64, byRef b as uint64)
 
  r = a + b
 
endproc