aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNic Gaffney <gaffney_nic@protonmail.com>2023-06-15 18:08:01 -0500
committerNic Gaffney <gaffney_nic@protonmail.com>2023-06-15 18:08:01 -0500
commit16413ca19668bb90a92f2620996dc555e798a0c7 (patch)
tree4bebad5033e7d8b5046539d18245b846be83ded2
parenta8c0785c8104568fc57d1cd910c266e6775e865b (diff)
downloadsloth-16413ca19668bb90a92f2620996dc555e798a0c7.tar.gz
STDs lmao
-rw-r--r--sloth/src/std.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/sloth/src/std.rs b/sloth/src/std.rs
new file mode 100644
index 0000000..cae9aaa
--- /dev/null
+++ b/sloth/src/std.rs
@@ -0,0 +1,21 @@
+use rand::Rng;
+
+use std::ffi::CString;
+
+#[no_mangle]
+pub extern "C" fn rand(a: i64, b: i64) -> i64 {
+ let value = rand::thread_rng().gen_range(a..b);
+ return value;
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn println(s: *const c_char) {
+ let s = unsafe { CStr::from_ptr(s) }.to_str().unwrap();
+ println("{s}");
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn print(s: *const c_char) {
+ let s = unsafe { CStr::from_ptr(s) }.to_str().unwrap();
+ print("{s}");
+}