-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogging.rs
More file actions
73 lines (67 loc) · 2.18 KB
/
Copy pathlogging.rs
File metadata and controls
73 lines (67 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use crate::{StdFunction, StdlibModule, StdlibRegistry};
use std::collections::HashMap;
use std::rc::Rc;
use techscript_runtime::{error::RuntimeError, value::RuntimeValue};
impl StdlibRegistry {
pub fn register_logging(&mut self) {
let mut exports: HashMap<String, Rc<dyn techscript_runtime::function::Callable>> =
HashMap::new();
exports.insert(
"info".to_string(),
Rc::new(StdFunction {
name: "info".to_string(),
arity: 1,
callback: |_ctx, args| {
let msg = args[0].try_into_string()?;
println!("[INFO] {}", msg);
Ok(RuntimeValue::Null)
},
}),
);
exports.insert(
"warn".to_string(),
Rc::new(StdFunction {
name: "warn".to_string(),
arity: 1,
callback: |_ctx, args| {
let msg = args[0].try_into_string()?;
println!("[WARN] {}", msg);
Ok(RuntimeValue::Null)
},
}),
);
exports.insert(
"error".to_string(),
Rc::new(StdFunction {
name: "error".to_string(),
arity: 1,
callback: |_ctx, args| {
let msg = args[0].try_into_string()?;
eprintln!("[ERROR] {}", msg);
Ok(RuntimeValue::Null)
},
}),
);
exports.insert(
"debug".to_string(),
Rc::new(StdFunction {
name: "debug".to_string(),
arity: 1,
callback: |_ctx, args| {
let msg = args[0].try_into_string()?;
println!("[DEBUG] {}", msg);
Ok(RuntimeValue::Null)
},
}),
);
self.register_module(
"std.logging",
StdlibModule {
name: "std.logging".to_string(),
version: "1.0.0".to_string(),
exports,
required_capabilities: Vec::new(),
},
);
}
}