#![no_std]
extern crate alloc;
use alloc::boxed::Box;
use engine_internals::engine_startup;
use pixel_format::Rgba64;
// use core::fmt::Result;
use core::result::Result;
use rhai::{EvalAltResult, Scope};

mod engine_internals;
pub mod pixel_format;

pub const SHADER: &str = include_str!("../shaders/simple.shade");

pub fn evaluate_shader(x: usize, y: usize, pixel: Rgba64) -> Result<Rgba64, Box<EvalAltResult>> {
    let engine = engine_startup();

    let ast = engine.compile(SHADER)?;
    let mut scope = Scope::new();

    scope.push("PIXEL_RGBA", pixel);
    scope.push("PIXEL_X", x);
    scope.push("PIXEL_Y", y);

    let result: Rgba64 = engine.call_fn(&mut scope, &ast, "main", ())?;

    Ok(result)
}
