File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ pub mod array;
6
6
pub mod fs;
7
7
pub mod string;
8
8
pub mod math;
9
+ pub mod random;
9
10
/// Function to load a standard library
10
11
/// # Arguments
11
12
/// * `lib` - The name of the library to load.
@@ -23,6 +24,7 @@ pub fn get_std_lib(lib: String) -> Option<Res> {
23
24
"nya:whiskers" => Some ( string:: add_globals ( ) ) ,
24
25
"nya:scratchpad" => Some ( fs:: add_globals ( ) ) ,
25
26
"nya:catculator" => Some ( math:: add_globals ( ) ) ,
27
+ "nya:rundamn" => Some ( random:: add_globals ( ) ) ,
26
28
//"nya:meowternet" => Some(http::add_globals()),
27
29
_ => None ,
28
30
}
Original file line number Diff line number Diff line change @@ -2,6 +2,22 @@ extern crate rand;
2
2
use rand:: seq:: SliceRandom ;
3
3
use rand:: Rng ;
4
4
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
+ }
5
21
pub struct SimpleRandom {
6
22
rng : rand:: rngs:: ThreadRng ,
7
23
}
You can’t perform that action at this time.
0 commit comments