Types

A variable can have different types, such as string, bool or number. Since Lunaris is a dynamic programming language, the type of a variable can be changed.

String

// Anything
message = "Hello World";

A string represents text and is declared by enclosing anything with a double quotation (“ “)

Bool

isNpcAlive = true;
isNpcAlive = false;
isNpcAlive = hp > 0; // If the HP is larger than 0, it's true otherwise false

A bool represents either true or false. You can assign a bool value by using the true/false literals, or by an expression.

Number

a = 12.5;
b = 7.5;
c = a + b; // 20 (12.5 + 7.5)

A number represents a decimal numeric value.

Nil

local message = nil;

A nil represents that the variable does not have any value. In other language this is sometimes also called null or undefined.

Function

function HelloWorld() {
    print("Hello World")
}
HelloWorld() // Hello World

A function is a reusable block of code.

Table

A table is Lunaris’ general-purpose structured data container. Use a table when you want to group values together without defining a named type.

Other language features build on the same idea of structured data, but add more rules and meaning:

  • Array are used for ordered lists of values
  • Class defines reusable object types
  • Enum defines named constant values
  • Exception represents structured error information
local myTable = {
    Message = "Hello"
}

print(myTable.Message)

myTable.Message = "Hello World"
print(myTable.Message)

myTable.Message = nil
print(myTable.Message)

Tuples

A tuple is a value that groups multiple values together. It is useful when a function should return more than one value as a single result.

function GetPlayerInfo() {
    return "Lithrun", 26
}
local name, level = GetPlayerInfo()
print(name) // Lithrun
print(level) // 26

Userdata

userdata is a host object exposed to Lunaris. It behaves similarly to an object with fields and methods, but it is backed by Erios/C# code rather than by a native Lunaris table.

Categories:

Updated: