(func...)
Create a function that can be called internally by other functions and exported so that it can to be called by JavaScript.

Syntax

(func $label (export...) (param...) (result...))

Parameters

$label Optional
The name of the function. If the function is not exported, and will be used internally within another functions, then the label will be required. If you are exporting the function, and not using it internally, then you do not need to give a label.
(param...) Optional
Lists all the parameters the function is given. All the parameters are pushed onto the stack before the function is called. They are then popped off the stack and placed inside local variables within the function. There can be more than one param object.
(result...) Optional
Details about the returning results pushed onto the stack when the function ends. You can only have one result object, but can give more than one returning data type.
(export...) Optional
Export information to allow the function can be called by JavaScript.

Examples

(func $add (param $first i32) (param $second i32) (result i32)
  ;; Add first and second parameters together and return result
  local.get $first
  local.get $second
  i32.add
)
(func (export "add") (param $first i32) (param $second i32) (result i32)
  ;; Add first and second parameters together and return result
  local.get $first
  local.get $second
  i32.add
)