zlang 0.1.1

a simple embeddable language implemented for rust, it is called zlang because it is the last embedded language a sane developer would reach for.
Documentation
  • Coverage
  • 0%
    0 out of 18 items documented0 out of 7 items with examples
  • Size
  • Source code size: 17.28 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.09 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • WebAppEnjoyer
use std::rc::Rc;
use zlang::{ZLang, ZType, ZData};

struct MyState {}

fn main() {
    let mut lang: ZLang<MyState> = ZLang::new();

    lang.register_function(
        "inspect_data",
        |_state: &mut MyState, _interp: &ZLang<MyState>, args: Vec<ZType>| {
            for z in args {
                match &z.data {
                    ZData::Raw(bytes) => {
                        println!("Raw bytes: {:?}", bytes);
                    }
                    ZData::Dyn(any) => {
                        if z.tag == Rc::<str>::from("string") {
                            let s = any.downcast_ref::<String>().unwrap();
                            println!("String: {}", s);
                        } else if z.tag == Rc::<str>::from("num") {
                            let n = any.downcast_ref::<i64>().unwrap();
                            println!("Number: {}", n);
                        } else {
                            println!("Other dynamic type with tag {}", z.tag);
                        }
                    }
                }
            }
            None
        },
    );

    // Example program
    let program = r#"
        inspect_data("Hello world")
    "#;

    lang.interpret(&mut MyState {}, program);
}