inkcpp
Loading...
Searching...
No Matches
ink::runtime::runner_interface Class Referenceabstract

A runner to execute ink script from a story. More...

#include <runner.h>

Public Member Functions

virtual void set_rng_seed (uint32_t seed)=0
 Sets seed for PRNG used in runner.
 
virtual bool move_to (hash_t path)=0
 Moves the runner to the specified path.
 
virtual bool can_continue () const =0
 Can the runner continue?
 
virtual const char * getline_alloc ()=0
 Continue execution until the next newline, then allocate a c-style string with the output.
 
virtual snapshotcreate_snapshot () const =0
 creates a snapshot containing the runner, globals and all other runners connected to the globals.
 
virtual std::string getline ()=0
 Gets the next line of output using C++ STL string.
 
virtual void getline (std::ostream &)=0
 Gets the next line of output using C++ STL string.
 
virtual std::string getall ()=0
 Gets all the text until the next choice or end.
 
virtual void getall (std::ostream &)=0
 Gets all the text until the next choice or end.
 
virtual FString getline ()=0
 Gets the next line of output using unreal string allocation.
 
virtual const choicebegin () const =0
 Choice iterator.
 
virtual const choiceend () const =0
 Terminal choice iterator.
 
virtual void choose (size_t index)=0
 Make a choice.
 
virtual bool has_tags () const =0
 check if since last choice selection tags have been added
 
virtual size_t num_tags () const =0
 return the number of current.
 
virtual const char * get_tag (size_t index) const =0
 access tag.
 
template<typename F >
void bind (hash_t name, F function, bool lookaheadSafe=false)
 Binds an external callable to the runtime.
 
template<typename F >
void bind (const char *name, F function, bool lookaheadSafe=false)
 Binds an external callable to the runtime.
 
template<typename D >
void bind_delegate (hash_t name, D functionDelegate, bool lookaheadSafe)
 bind and unreal delegate
 
 operator bool () const
 Shortcut for checking if the runner can continue.
 
bool has_choices () const
 Checks if we're currently facing any choices.
 
size_t num_choices () const
 Returns the number of choices currently available.
 
const choiceget_choice (size_t index) const
 Gets a choice.
 
const choiceoperator[] (size_t index)
 Shorcut for accessing a choice.
 

Detailed Description

A runner to execute ink script from a story.

An independant runner which can execute ink script from a story independant of other runners. Think of the ink story object like an executable file and the runners as 'threads' (not to be confused with ink threads, which are a language feature). Runners track their own instruction pointer, choice list, temporary variables, callstack, etc. They can either be started with their own globals store, or can share one with other runner instances.

See also
globals
story

Member Function Documentation

◆ begin()

virtual const choice * ink::runtime::runner_interface::begin ( ) const
pure virtual

Choice iterator.

Iterates over choices the runner is currently facing.

See also
end
Returns
constant iterator to the first choice

◆ bind() [1/2]

template<typename F >
void ink::runtime::runner_interface::bind ( const char * name,
F function,
bool lookaheadSafe = false )
inline

Binds an external callable to the runtime.

Given a name and a callable object, register this function to be called back from the ink runtime.

Parameters
namename string
functioncallable
lookaheadSafeif false stop glue lookahead if encounter this function this prevents double execution of external functions but can lead to missing glues

◆ bind() [2/2]

template<typename F >
void ink::runtime::runner_interface::bind ( hash_t name,
F function,
bool lookaheadSafe = false )
inline

Binds an external callable to the runtime.

Given a name and a callable object, register this function to be called back from the ink runtime.

beside an exact signature match, the function can also have one of the following signatures:

  • void(size_t argl, const ink::runtime::value* argv)
  • ink::runtime::value(size_t argl, const ink::runtime::value* argv) this provides a generic way to bind functions with abitrary length
    Parameters
    namename hash
    functioncallable
    lookaheadSafeif false stop glue lookahead if encounter this function this prevents double execution of external functions but can lead to missing glues

◆ bind_delegate()

template<typename D >
void ink::runtime::runner_interface::bind_delegate ( hash_t name,
D functionDelegate,
bool lookaheadSafe )
inline

bind and unreal delegate

Parameters
namehash of external function name in ink script
functionDelegate
lookaheadSafebind()

◆ can_continue()

virtual bool ink::runtime::runner_interface::can_continue ( ) const
pure virtual

Can the runner continue?

Checks if the runner can continue execution. If it can't, we are either at a choice or are out of content.

See also
continue
has_choices
Returns
Can continue be called

◆ choose()

virtual void ink::runtime::runner_interface::choose ( size_t index)
pure virtual

Make a choice.

Takes the choice at the given index and moves the instruction pointer to that branch.

Parameters
indexindex of the choice to make

◆ create_snapshot()

virtual snapshot * ink::runtime::runner_interface::create_snapshot ( ) const
pure virtual

creates a snapshot containing the runner, globals and all other runners connected to the globals.

See also
story::new_runner_from_snapshot, story::new_globals_from_snapshot

◆ end()

virtual const choice * ink::runtime::runner_interface::end ( ) const
pure virtual

Terminal choice iterator.

Pointer past the last choice the runner is currently facing.

See also
begin
Returns
end iterator

◆ get_choice()

const choice * ink::runtime::runner_interface::get_choice ( size_t index) const

Gets a choice.

Returns the choice object at a given index

See also
num_choices
Parameters
indexindex of the choice to access
Returns
choice object with info on the choice

◆ get_tag()

virtual const char * ink::runtime::runner_interface::get_tag ( size_t index) const
pure virtual

access tag.

Parameters
indextag id to fetch [0;num_tags())

◆ getall() [1/2]

virtual std::string ink::runtime::runner_interface::getall ( )
pure virtual

Gets all the text until the next choice or end.

Continue execution until the next choice or the story ends, then return the output as an STL C++ std::string. Requires INK_ENABLE_STL

Returns
std::string with the next line of output

◆ getall() [2/2]

virtual void ink::runtime::runner_interface::getall ( std::ostream & )
pure virtual

Gets all the text until the next choice or end.

Continue execution until the next choice or the story ends, then return the output to an STL C++ std::ostream. Requires INK_ENABLE_STL

◆ getline() [1/3]

virtual std::string ink::runtime::runner_interface::getline ( )
pure virtual

Gets the next line of output using C++ STL string.

Continue execution until the next newline, then return the output as an STL C++ std::string. Requires INK_ENABLE_STL

Returns
std::string with the next line of output

◆ getline() [2/3]

virtual FString ink::runtime::runner_interface::getline ( )
pure virtual

Gets the next line of output using unreal string allocation.

Continue execution until the next newline, then return the output as an Unreal FString. Requires INK_ENABLE_UNREAL

Returns
FString with the next line of output

◆ getline() [3/3]

virtual void ink::runtime::runner_interface::getline ( std::ostream & )
pure virtual

Gets the next line of output using C++ STL string.

Continue execution until the next newline, then return the output to an STL C++ std::ostream. Requires INK_ENABLE_STL

◆ getline_alloc()

virtual const char * ink::runtime::runner_interface::getline_alloc ( )
pure virtual

Continue execution until the next newline, then allocate a c-style string with the output.

This allocated string is managed by the runtime and will be deleted at the next choose() or getline()

Returns
allocated c-style string with the output of a single line of execution

◆ has_choices()

bool ink::runtime::runner_interface::has_choices ( ) const
inline

Checks if we're currently facing any choices.

Returns
are there any choices available

◆ move_to()

virtual bool ink::runtime::runner_interface::move_to ( hash_t path)
pure virtual

Moves the runner to the specified path.

Clears any execution context and moves the runner to the content at the specified path.

Parameters
pathpath to search and move execution to
Returns
If the path was found

◆ num_choices()

size_t ink::runtime::runner_interface::num_choices ( ) const

Returns the number of choices currently available.

Returns
number of choices

◆ num_tags()

virtual size_t ink::runtime::runner_interface::num_tags ( ) const
pure virtual

return the number of current.

The tags will be accumulated since last choice order of tags wont change, and new are added at the end

◆ operator bool()

ink::runtime::runner_interface::operator bool ( ) const
inline

Shortcut for checking if the runner can continue.

See also
can_continue

◆ operator[]()

const choice * ink::runtime::runner_interface::operator[] ( size_t index)
inline

Shorcut for accessing a choice.

See also
get_choice
Parameters
indexindex of the choice to access
Returns
choice object with info on the choice

◆ set_rng_seed()

virtual void ink::runtime::runner_interface::set_rng_seed ( uint32_t seed)
pure virtual

Sets seed for PRNG used in runner.

Else runner is started with the current time as seed.

Parameters
seedseed to use for PRNG

The documentation for this class was generated from the following file: