1use coda_runtime::env::Env;
2
3pub mod io;
4pub mod math;
5
6pub type StdRegisterFn = fn(&mut Env);
7
8pub fn get_module(path: &str) -> Option<StdRegisterFn> {
9 match path {
10 "std.math" => Some(math::register),
11 "std.io" => Some(io::register),
12 _ => None,
13 }
14}
15
16pub fn std_loader(
17 path: &str,
18 env: &mut Env,
19) -> Result<bool, Box<dyn std::error::Error>> {
20 if path.starts_with("std.") {
21 match path {
22 "std.math" => {
23 math::register(env);
24
25 return Ok(true);
26 }
27
28 "std.io" => {
29 io::register(env);
30
31 return Ok(true);
32 }
33
34 _ => {
35 return Err(format!("unknown std module `{path}`").into());
36 }
37 }
38 }
39
40 Ok(false)
41}