Skip to main content

ling_runtime/
std.rs

1//! Ling standard library — built-in functions exposed to the runtime.
2
3/// Print a value to stdout with a trailing newline.
4pub fn ling_print(s: &str) { println!("{s}"); }
5
6/// Print a debug representation.
7pub fn ling_debug(s: &str) { eprintln!("[debug] {s}"); }
8
9/// Abort with a message.
10pub fn ling_panic(msg: &str) -> ! { panic!("{msg}"); }
11
12/// Sleep for `ms` milliseconds (useful for simple animations / demos).
13pub fn ling_sleep_ms(ms: u64) {
14    std::thread::sleep(std::time::Duration::from_millis(ms));
15}
16
17/// Current Unix timestamp in seconds.
18pub fn ling_time() -> f64 {
19    std::time::SystemTime::now()
20        .duration_since(std::time::UNIX_EPOCH)
21        .map(|d| d.as_secs_f64())
22        .unwrap_or(0.0)
23}