-
Notifications
You must be signed in to change notification settings - Fork 5
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;
}
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*
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;
}
}
Wiki created by @solar-mist and @Kami