Skip to main content

Function Types

In LemonScript, functions can have types too. Firstly, lets talk about the function return types. The compiler will throw an error if it recieves a return type that doesn't match the function's return type. You can set the return types to a function like this:

func [function name]([args]): [type1] | [type2] ... {    [code]}

If no return type is specified, then the return type is automatically set to Any, allowing any return type.

You can also set types for the arguments of a function. For example:

func addNums(num1: Number, num2: Number): Number {    return num1 + num2}
print(addNums(1, "two"))

This script will error because the second argument passed into the addNums function is not a number type, as required in the function args.