From 16413ca19668bb90a92f2620996dc555e798a0c7 Mon Sep 17 00:00:00 2001 From: Nic Gaffney Date: Thu, 15 Jun 2023 18:08:01 -0500 Subject: STDs lmao --- sloth/src/std.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 sloth/src/std.rs 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}"); +} -- cgit v1.2.3