Class: Script

PodJS. Script

Executable sequence of blocks that is associated with a resource.

new Script(context)

Constructs a new Script bound to the environment and resource provided in the given context object.
Parameters:
Name Type Description
context PodJS.ScriptContext containing the environment and resource this script is bound to.
Source:

Members

context :PodJS.ScriptContext

The context, containing a reference to the environment and resource the script is bound to.
Type:
Source:

index :number

The instruction pointer to which block number is next to be executed.
Type:
  • number
Source:

ipStack :number

Stack of instruction pointers for begin / end pairs.
Type:
  • number
Source:

scriptHasError :boolean

If true, this script has an error, so it is disabled.
Type:
  • boolean
Source:

yield :boolean

Mechanism that allows a block to signal that the script is ready to yield because enough was done for this tick.

Before each script tick, yield is set to false and blocks are executed until one block sets yield to true. At that point, the next instruction will be executed in the next cycle.

Type:
  • boolean
Source:

Methods

addBlock(block)

Adds the given block to the end of the script.
Parameters:
Name Type Description
block PodJS.Pod#Block The instance of the block to add.
Source:

getBlocks() → {PodJS.Resource#Block[]}

Returns a clone of the sequence of blocks present in this script.

A clone is returned so the caller cannot accidentally mutate the script without the script being aware.

Source:
Returns:
A clone of the sequence of blocks
Type
PodJS.Resource#Block[]

nextArgument() → {string|number}

Advance the IP and read the next block as an argument. Note the block might be composite, causing additional blocks to be read (e.g. in the case of something like add.c(1).c(2)). This method is typically called by a block implementation.
Source:
Returns:
A constant value to be interpreted by the block
Type
string | number

nextBlock()

Advances the instruction pointer to the next block
Source:

peekBlock()

Peeks at the block at the current IP but does not advance the iP.
Source:
Returns:
The block at the current IP or null if no block there.

popIP()

Pops the current instruction pointer from the stack (usually done at the end of a loop).
Source:

pushIP()

Pushes the current instruction pointer to the stack (usually done just before a loop).
Source:

reset()

Reset this script to the first instruction.
Source:

skipBeginEndBlock()

Start at the begin block and advance the IP past the next matching end block, skipping all blocks in-between.
Source:

tick()

Gets called by the environment when this script is active.

Pods are not responsible for calling tick() on their own scripts. That is taken care of by the environment.

Source: