Skip to content
/ zap Public

a scripting language (primarily) for games written in Rust

Notifications You must be signed in to change notification settings

xor-bits/zap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zap

a programming language for (game) scripting

strongly typed, type inference, scripting language, interop, LLVM JIT

Hello world + Fibonacci sequence

fib := fn() {
    a := 0;
    b := 1;
    for {
        // TODO: f-strings
        print(f"{a}");

        tmp := a + b;
        a = b;
        b = tmp;
        // TODO: a, b = b, a + b;
    };
};

str := "Hello, world!";

main := () -> i32 {
    print(str);
    fib();
    return 0;
};

Usage from Rust

let mut compiler = Compiler::new();
compiler.add("sum", |a: i32, b: i32| a + b).unwrap();
compiler.add("print", |a: i32| println!("{a}")).unwrap();
compiler.run(r#"
    main := () -> i32 {
        print(sum(40, 2));
        0
    }
"#).unwrap();

TODO

the global scope should be the main function, maybe?

so this:

s := "test";
print(s);

instead of:

s := "test";
main := () -> i32 {
    print(s);
    return 0;
}

Releases

No releases published

Packages

No packages published