Function
The func keyword is used to define functions in GLuaX. Functions can be declared at the top level (as items) or inside other items like impl blocks. Functions consist of a name, a parameter list, an optional return type, and a body.
Syntax
Section titled “Syntax”[pub] func name(param1: Type1, param2: Type2, ...Type) [!] -> ReturnType { // function body}- The return type is optional; if omitted, the function implicitly returns
nil. - Use
...Typeas a parameter for varargs.
Example
Section titled “Example”func add(a: number, b: number) -> number { a + b}
func return_two() -> (number, number) { (2, 2)}// ORfunc return_two() -> (number, number) { return 2, 2;}
func errorable_func() ! { throw "An error occurred";}- Functions can be marked
pubto make them accessible outside the module. - The
!after the parameter list (e.g.,func foo() !) indicates the function can return an error (errorable function). - Variadic parameters (
...Type) must be the last in the parameter/return list.