Crate throne[][src]

Expand description

Throne is a game scripting language for prototyping and story logic.

Documentation for learning the language itself can be found on Github.

Example

use throne::{ContextBuilder, tokenize};

// Write your script text inline or in an external file included with `include_str!(..)`
let script = r#"
Mary is sister of David
Sarah is child of Mary
Tom is child of David

CHILD is child of PARENT . AUNT is sister of PARENT .
    COUSIN is child of AUNT = COUSIN is cousin of CHILD
"#;

// Build the Throne context using your script text to define the initial state and rules
let mut context = ContextBuilder::new()
    .text(script)
    .build()
    .unwrap_or_else(|e| panic!("Failed to build Throne context: {}", e));

// Execute an update step
context.update().unwrap_or_else(|e| panic!("Throne context update failed: {}", e));

// Fetch the updated state
let state = context.core.state.get_all();

// Convert a string to a Throne phrase
let expected_state_phrase = tokenize("Sarah is cousin of Tom", &mut context.string_cache);

assert_eq!(state, vec![expected_state_phrase]);

Re-exports

pub use crate::token::tokenize;
pub use crate::token::Phrase;
pub use crate::token::PhraseGroup;
pub use crate::token::PhraseString;
pub use crate::token::Token;

Modules

Structs

References a string or integer stored in a StringCache.

Stores the State, Rules and Atom mappings for a Throne script.

Used to build a Context.

Stores the State and Rules for a Context.

References a Phrase in a State.

Represents a Throne rule.

Stores a set of Phrases.

Stores the mappings between a set of Atoms and the primitives that they reference.

Traits

Functions

A free function equivalent to Context::update_with_side_input if required to avoid lifetime conflicts.