com.example.Weather, and each function has named, typed parameters and a return type. Ask your server’s administrator for the resources available to you.
Bind a resource
To use a resource, bind it to a name with aconst declaration whose type is the resource’s full path and name:
- Resource bindings must use
const, notvar. - A resource binding has no
= value. - The resource is looked up when the declaration runs. If the server has no resource with that path and name, the script fails with
Unknown resource 'com.example.Weather'.
Call a function
Call a function on a bound resource with dot notation and named arguments:- Every declared parameter must be passed:
Missing argument 'city' for function 'temperature'. - Unknown or duplicate argument names are errors.
- Each argument must match its parameter’s type, with numeric promotion applied:
Cannot use a int32 value as string for argument 'city' of 'temperature'.
RuntimeErrors that stop the script, because they’re bugs in the script rather than conditions it can recover from.
Use the result
A function call never evaluates to the bare return value. It always evaluates to a result object with avalue and an error:
.value, and check .error first if the call can fail:
Call a function for its side effect
If you don’t need a function’s result, call it as a statement on its own:.error if the outcome matters.
Resource references aren’t values
A bound resource can only be used to call its functions. You can’t:- Return it, or store it in an object or list.
- Interpolate it into a string.
- Read a function without calling it, such as
weather.temperature.
A resource reference cannot be used as a value.