Any public exposed function can be an App Function.
An App Function may have arguments (parameters). Although empty function (no argument) is allowed, it is not common.
Arguments must be of compatible types as explained below.
A “primitive type” is a simple type.
- Boolean - Has two possible values; true or false.
- Number - A real number, both integer and floating point is allowed.
- String - A string value. Empty string with 0 length is allowed by default, unless otherwise constrained.
- Enumeration - Internally it is an integer. If Enumeration has n items, the value range is [0, n-1].
- DateTime - Combination of a date and time. Internally it’s value is a number of seconds from Unix Epoch. Floating point is allowed with at least millisecond of precision.
- TimeOnly - Seconds from midnight. Internally it’s value a number. floating point is allowed with at least millisecond of precision.
- Device - A logical device. Internally it is an integer number of device internal ID.
- LanDevice - A 3rd party Wi-Fi/Ethernet. Internally it is an integer number of device internal ID.
- VirtualDevice - An App emulated logical device. Internally it is an integer number of device internal ID.
- User - A Liberty IoT Hub user or a user group. Internally it is an integer number of user (or user group) ID.
Enumeration type must be given the list of names.
Enumeration can be translated into any other display languages, for example, Chinese.
There are only two complex types in the system, List (array) and Table (struct).
- List - List represents an array of homogeneous type, i.e. all items in a list must have the same type.
- Table - Table is a struct, which is a collection of key-value pairs. Key is the name, value may be of any type.
Both List and Table can be nested to create a data structure of arbitrarily finite depth.
Primitive type can be considered a tree with only one single node.
The function name, combined with the description of the structure of each argument, is called function signature.
Lua is a dynamic type language. The type can not be inferred automatically through reflection such as in .Net. It can’t be inferred through static code analysis either. So Liberty-IoT Studio features a signature editor so that developer has to manually specify the function signatures.
Below is the signature of “Holiday Light Show” function shipped with Liberty IoT Hub.
Note for members of a Table/struct, the name (key) must be specified by developer in “Native Name” column to match the actual name in code.
Client UI Optimization
Combined with Attributes, data types can be optimized on client UI (e.g. Smartphone).