Crate databind[][src]

Expand description

Expand the functionality of Minecraft Datapacks.

CLI

If you’re just looking to use Databind as a tool and not to make your own Rust project with it, then you can use the CLI. Documentation for it is available here.

Quick Start

Here’s some code to compile a given string and print the output for each file:

use databind::compiler::Compiler;
use std::collections::HashMap;

// Source file
let source_file = "
func main\n\
    say Hello, World!\n\
end\n\
func second_func\n\
    say Second function\n\
end"
.to_string();
// Create compiler and tokenize source file
let mut compiler = Compiler::new(source_file, None);
let tokens = compiler.tokenize();
// Compile tokens to files
let compiled = compiler.compile(tokens, None, "", &HashMap::new(), false);
// Print the contents of each file
for (k, v) in compiled.filename_map.iter() {
    println!("Output File: {}.mcfunction", k);
    println!("Contents:\n{}", compiled.file_contents[*v]);
    println!("----------");
}

The code above results in the following output:

Output File: main.mcfunction
Contents:
say Hello, World!
----------
Output File: second_func.mcfunction
Contents:
say Second function
----------

Modules

Contains functions and structs used to tokenize and compile Databind source code

Contains functions used by the CLI to get information from files or to create files

Contains type definitions used throughout the project

Structs

Settings for the compiler

Enums

The enum of Databind tokens used for tokenization of Databind source files