HitoriScript allows you to take full advantage of the Hitori Engine in an easy and non-repetitive way. Instead of writing Rust code, where function calls and repeated declarations can be stressful and tedious, Hitori enables an entire scripting language that compiles into a no-compensations and speedy language.
label main {
scene new
with bg "bg/west1"
with char "char/maya"
scene swap
show maya "smile" at right
dialogue maya "This is a HitoriScript example!"
}HitoriScript has a C-like syntax, where variables are defined with the simple var statement. Instead of operators and functions, HitoriScript has only one functionality method: operators.
Everything that creates a change in the state of the Hitori engine or the script interpreter is called an Operator. Operators are basically references to Rust functions. An Operator may either make a state change in the Hitori engine, or make a change in the script either by pushing to the accumulator stack, making a modification to a variable, or returning a value.
Take this example for thought:
label main {
debug "Debug message."
}Hitori takes care of mapping the operator in the script to the operator in Rust. All you need to know is what to type. The debug operator takes in a string and produces no (nil) output. In Rust, the debug operator is defined like so:
pub fn operator_debug(msg: &str, ctx: OperatorContext) -> OperatorResult<()> {
trace!("[{}] {}", ctx.interpreter().script_name(), msg);
OperatorResult::Good(())
}Operators in Hitori are matched by their definitions at compile time, and then called by loading them into a table at runtime. Each line is attempted to be matched against every operator that the compiler has loaded. A simple operator definition looks something like this:
dialogue <ch:char> <text:str>
This operator will match to any line that starts with the keyword dialogue, then an identifier as a var with a type char, and an identifier (or literal) with the type str. It will map the operator parameters ch and text to the parameters on the operator. Lets try something a bit harder:
show <ch:char> <panel:str> ?(at <pos:>{ right = 0; middle = 1; left = 2; })
This operator will match to any line that starts with the keyword show, then an identifier as a var with the type char, then an identifier (or literal) with the type str. The group identifier ?(..) specifies that the matches in the group are optional and the captured types in the group are optional. This also match any line that ends with the keyword at followed by a single word selection from the three in the map.
The full syntax for the operator definitions are in a different document.