User defined Classes

LunaAVR lets you define your own classes, as a module or library. Such a class can be implemented in the main program. Such a class is self contained. The components are accesssible only via the class name (different namespace: „ClassName.xxx“). The different Namespace allows to use names for the components that also exists in the main program.

A class may contain these components:

The individual components are declared within the class similar to the main program and then be a part of the class.

  • Class Identifier
    • Constants declaration
    • Definitions/Aliases
    • Structure Declarations
    • Variable dimensioning
    • Interrupt-Service Routines
    • Functions and Procedures
    • Data structures
  • endClass

Using classes in the program code

You can acces all components of a class from your program code:

  • Structure Declarations (for dimensioning)
  • Constantes (read)
  • Variables (read and write)
  • Procedures (call)
  • Funktions (call)
  • (Data-) Structures (read and write)
' Initialization
[..]
dim var as single
'Somewhere in your program code
print test.Version       ' Output
test.Init()              ' Call Procedure
var = test.GetData(0,2)  ' Call Funktion
test.a=123               ' Assign value
print str(test.a)        ' Read value and output
 
' Main Loop
do
loop
 
' Declaration
Class test
  const Version = "1.0"
  dim a as byte
  Procedure Init()
    print "Initialization"
    print "a = "+str(a)
  endProc
 
  Function GetData(x as byte, y as byte) as single
    mul y,4
    y=y+x
    return table.SingleValue(y)
  endFunc
 
  data table
    .dw &h1234,&h5678,&h9aab
    .dw &h1234,&h5678,&h9aab
    .dw &h1234,&h5678,&h9aab
    .dw &h1234,&h5678,&h9aab
  enddata
endClass