Code glossary

This is a brief **glossary** of terms related to object-oriented programming in Lua and *Retro Gadgets*. For a more in-depth overview, check out the official Lua document on Object-Oriented programming.

## Objects

An object is an instantiation of a class. Each module in a gadget is an instance of their type of module, and therefore they're objects. For example, LcdDisplay is a type of module for text LCD displays, but to refer to the first LCD display in your gadget specifically you use gdt.Lcd0. The name of each individual object on a gadget can be checked using the Multitool. All of a gadget's modules can be found inside gdt as a table.

Note that modules which can only appear once in a gadget, such as ROM and PowerButton won't have a number at the end of their names in the gdt table, for example gdt.ROM and gdt.PowerButton.

## Properties

A property is a value that can be read or set in an object. For example, it can be used to check the current condition of a module, or modify it.

It should be called with object.property.

Examples:

```
gdt.Led0.State = gdt.LedButton0.ButtonState

```

This sets the state of a LED Led0 to be the same as the incoming state of the button LedButton0. What will happen is that the LED will turn on as long as the button is pressed down.

```
gdt.Lcd0.Text = "Hello world!"

```

This will set the text property of an LCD screen Lcd0 to the string "Hello world!", displaying it.

On the wiki, properties are documented as follows:

read only
**property** type
description of the property

The name of the property is highlighted in bold. The type of that property is marked in orange If the property can only be read, and not set, it will be marked as read only in the upper right corner. If a type is surrounded by one of more {curly brackets}, that means that it's a table.

## Methods

A method is a function which receives additional arguments to carry out a task.

Unless a method is determined to be a global method, it needs to be called in relation to a specific object. In order to do so, you must call it with object:method(argument). This way, with :, you are telling the function that what it expects to be the self argument is the object.

Example:

```
gdt.AudioChip0:Play(sample, 1)

```

This will tell the AudioChip AudioChip0 to play a previously loaded sample sample on channel 1.

If a method is global, it can be called by itself, or if is static and part of a generic class, with a . like so: class.method(argument).

Example:

```
desk.SetLampState(true)

```

This will turn on the desk lamp.

On the wiki, methods are documented as follows:

**method**( argument1 type, argument2 type ) returnType
description of the method

The name of the method is highlighted in bold. The arguments are shown between parentheses and each of them has a respective type they expect. If the method returns a value, the type it returns is marked at the end. If a type is surrounded by one of more {curly brackets}, that means that it's a table.

## Events

An event is triggered by a module external to the CPU. For example the Wifi module triggers an event when a web request returns a response. To handle events, you must select the module that raises the event on your CPU's EventChannels and a specially named function eventChannelN, where N must be replaced by the number of your channel, will run when the event is triggered. The event channel function receives the module that triggered the event, and a table containing values pertaining to that event.

Example:

```
function eventChannel1(sender, event)
    log("got event " .. tostring(event) .. " from module " .. tostring(sender))
end

```

This function will handle incoming events on channel 1, once the module connected to that channel sends the CPU an event, it will print out to the Multitool debug console the string representation of the event table event and the name of the module sender that sent it.

On the wiki, event types are documented as follows:

**eventType** : { value1 type, value2 type }
description of the event type

The type associated with the event's table is highlighted in bold. The contents of the table are shown between curly brackets, each one with its associated type.