[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / command/function/runtime

# command/function/runtime

## Classes

- [FunctionRuntime](https://jsprismarine.dev/api/@jsprismarine/prismarine/command/function/runtime/classes/FunctionRuntime.md)

## Interfaces

### FunctionRunOutcome

Defined in: [packages/prismarine/src/command/function/runtime.ts:49](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L49)

What one call did, which is what `/function` and `execute if function`
read, plus the line count a tick reports.

#### Extends

- [`FunctionOutcome`](https://jsprismarine.dev/api/@jsprismarine/commands/index.md#functionoutcome)

#### Properties

##### commands

> `readonly` **commands**: `number`

Defined in: [packages/prismarine/src/command/function/runtime.ts:55](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L55)

How many command lines reached the dispatcher. The same as `result`
for a function that never reached a `/return`, and the honest number
for one that did.

##### matched

> `readonly` **matched**: `boolean`

Defined in: [packages/commands/src/host.ts:576](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/commands/src/host.ts#L576)

Whether any function the call ran returned a non-zero value through
`/return`. A tag matches when any of its members did, which is why
this is not `result !== 0`: members returning 1 and -1 sum to 0 and
still match.

###### Inherited from

[`FunctionOutcome`](https://jsprismarine.dev/api/@jsprismarine/commands/index.md#functionoutcome).[`matched`](https://jsprismarine.dev/api/@jsprismarine/commands/index.md#matched)

##### result

> `readonly` **result**: `number`

Defined in: [packages/commands/src/host.ts:569](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/commands/src/host.ts#L569)

What `/function` reports and `execute store result` captures: the sum
of the values `/return` produced, or the number of command lines that
ran when nothing the call reached returned a value.

###### Inherited from

[`FunctionOutcome`](https://jsprismarine.dev/api/@jsprismarine/commands/index.md#functionoutcome).[`result`](https://jsprismarine.dev/api/@jsprismarine/commands/index.md#result-1)

***

### FunctionRuntimeOptions

Defined in: [packages/prismarine/src/command/function/runtime.ts:59](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L59)

How to build a [FunctionRuntime](https://jsprismarine.dev/api/@jsprismarine/prismarine/command/function/runtime/classes/FunctionRuntime.md).

#### Properties

##### dispatch

> `readonly` **dispatch**: (`commandLine`, `source`) => [`CommandOutcome`](https://jsprismarine.dev/api/@jsprismarine/mcfunction/index.md#commandoutcome)

Defined in: [packages/prismarine/src/command/function/runtime.ts:68](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L68)

Runs one command line against a source, which is the server's vanilla
dispatcher. Injected rather than imported so the runtime is testable
without a dispatcher, and so nothing here depends on how a dispatch
reports its results.

###### Parameters

###### commandLine

`string`

###### source

[`CommandSource`](https://jsprismarine.dev/api/@jsprismarine/commands/index.md#commandsource)

###### Returns

[`CommandOutcome`](https://jsprismarine.dev/api/@jsprismarine/mcfunction/index.md#commandoutcome)

##### limits?

> `readonly` `optional` **limits?**: `Partial`\<[`ExecutionLimits`](https://jsprismarine.dev/api/@jsprismarine/mcfunction/index.md#executionlimits)\>

Defined in: [packages/prismarine/src/command/function/runtime.ts:72](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L72)

Overrides the two gamerule limits; see `DEFAULT_EXECUTION_LIMITS`.

##### loaded

> `readonly` **loaded**: [`ServerFunctions`](https://jsprismarine.dev/api/@jsprismarine/prismarine/command/function/load/index.md#serverfunctions)

Defined in: [packages/prismarine/src/command/function/runtime.ts:61](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L61)

The functions and tags the pack stack holds; see `loadServerFunctions`.

##### report

> `readonly` **report**: (`diagnostic`) => `void`

Defined in: [packages/prismarine/src/command/function/runtime.ts:70](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L70)

Where a diagnostic goes. The server sends these to its log.

###### Parameters

###### diagnostic

[`Diagnostic`](https://jsprismarine.dev/api/@jsprismarine/mcfunction/index.md#diagnostic)

###### Returns

`void`

## Variables

### MAX\_NESTED\_FUNCTION\_DISPATCH

> `const` **MAX\_NESTED\_FUNCTION\_DISPATCH**: `64` = `64`

Defined in: [packages/prismarine/src/command/function/runtime.ts:40](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L40)

How deep a `/function` may nest when the nesting goes back through the
dispatcher rather than through the executor's own queue.

A `function` line inside a function is control flow the executor reads
itself, so it stays on the executor's heap-allocated frame stack and is
bounded by `maxCommandSequenceLength`. `execute ... run function` is not:
it is a command, so it re-enters this runtime through a command body and
each level costs real JavaScript stack. Java has no such split, because
its `ExecutionContext` carries both, so this cap exists only to keep a
mutually recursive pack from overflowing the host stack before the
operation limit can stop it.
