add example compiler to demonstrate basic functionality and usage
This commit is contained in:
parent
96fe865ac1
commit
19c55b78f4
|
@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
- Macro strings
|
||||
- Function parameters/arguments
|
||||
- Example: barebones compiler
|
||||
|
||||
### Changed
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
//! This example demonstrates how to compile a shulkerscript file into a datapack using the shulkerscript compiler.
|
||||
//! Most basic version of a shulkerscript compiler, which takes a single input file and places the resulting datapack in the specified output directory.
|
||||
//!
|
||||
//! For a ready-to-use compiler, see the `shulkerscript-cli` crate.
|
||||
|
||||
use shulkerscript::{
|
||||
base::{FsProvider, PrintHandler},
|
||||
compile,
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "shulkerbox"))]
|
||||
compile_error!("Need feature 'shulkerbox' to compile this example");
|
||||
|
||||
fn main() {
|
||||
let mut args = std::env::args();
|
||||
let _ = args.next().unwrap();
|
||||
let input = args.next().expect("Expect path to shulkerscript file");
|
||||
|
||||
let output = args.next().expect("Expect path to output directory");
|
||||
|
||||
let code = compile(
|
||||
&PrintHandler::new(),
|
||||
&FsProvider::default(),
|
||||
shulkerbox::datapack::Datapack::LATEST_FORMAT,
|
||||
&[("main".to_string(), &input)],
|
||||
)
|
||||
.expect("failed to compile");
|
||||
|
||||
code.place(output).expect("failed to place datapack");
|
||||
}
|
Loading…
Reference in New Issue