Skip to content

Commit fc29d5a

Browse files
committed
changed librar essential
1 parent efeabe6 commit fc29d5a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/std_library/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod array;
66
pub mod fs;
77
pub mod string;
88
pub mod math;
9+
pub mod random;
910
/// Function to load a standard library
1011
/// # Arguments
1112
/// * `lib` - The name of the library to load.
@@ -23,6 +24,7 @@ pub fn get_std_lib(lib: String) -> Option<Res> {
2324
"nya:whiskers" => Some(string::add_globals()),
2425
"nya:scratchpad" => Some(fs::add_globals()),
2526
"nya:catculator" => Some(math::add_globals()),
27+
"nya:rundamn" => Some(random::add_globals()),
2628
//"nya:meowternet" => Some(http::add_globals()),
2729
_ => None,
2830
}

src/std_library/random.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@ extern crate rand;
22
use rand::seq::SliceRandom;
33
use rand::Rng;
44

5+
6+
pub fn add_globals() -> Res {
7+
let mut globals = HashMap::new();
8+
globals.insert(String::from("new"), Object::Inbuilt(new));
9+
globals.insert(String::from("random"), Object::Inbuilt(random));
10+
globals.insert(String::from("uniform"), Object::Inbuilt(uniform));
11+
globals.insert(String::from("randint"), Object::Inbuilt(randint));
12+
globals.insert(String::from("choice"), Object::Inbuilt(choice));
13+
globals.insert(String::from("shuffle"), Object::Inbuilt(shuffle));
14+
15+
16+
Res {
17+
globals,
18+
raw: None,
19+
}
20+
}
521
pub struct SimpleRandom {
622
rng: rand::rngs::ThreadRng,
723
}

0 commit comments

Comments
 (0)