Skip to content

Structs

solar-mist edited this page May 22, 2024 · 3 revisions

Defining Structs

To define a struct, the only required thing to be specified is a name. However, you may add any fields or member functions that your class requires. Example:

struct Test {
    bar: i32;
    func @getBar() -> i32 = this-> bar;
}

Fields

Struct fields are similar to variables, in that they require a type and a name. Currently, they may not have a default value. They can be assigned to or used like any other variables. They do not require the let keyword:

  • size: i32
  • message: i8*

Member Functions

Structs may have 0 or more member functions. They act similarly to regular functions although they can act directly on their objects and have an implicit parameter this which is a pointer to the class type. This parameter(named this) can be used to access fields in the object, or to call other member functions. Member functions must be defined inside their owning struct Example:

struct Foo {
    priv bar: i32;
    func getBar() -> i32 {
        return this->bar;
    }
}
Clone this wiki locally