Skip to content

Commit

Permalink
Merge pull request #4 from jupyterkat/main
Browse files Browse the repository at this point in the history
1620
  • Loading branch information
tigercat2000 authored Nov 18, 2023
2 parents d2e3b41 + 3ac193f commit 8430ae1
Show file tree
Hide file tree
Showing 19 changed files with 923 additions and 578 deletions.
2 changes: 1 addition & 1 deletion crates/byondapi-rs-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ crate-type = ["cdylib"]
[dependencies]
byondapi = { path = "../byondapi-rs" }
byondapi-sys = { path = "../byondapi-sys" }
tempfile = "3.8.0"
tempfile = "3.8.1"
test-cdylib = "1.1.0"
6 changes: 1 addition & 5 deletions crates/byondapi-rs-test/dm_project/dm_project.dme
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
if (ret.name != O.name)
throw EXCEPTION("Object did not make it through FFI")

/test/proc/send_test()
call_ext("byondapi_test.dll", "byond:send_test")()


/test/proc/test_ref()
var/turf/T = locate(1,1,1)
var/ret = call_ext("byondapi_test.dll", "byond:test_ref")(T)
Expand Down Expand Up @@ -87,7 +83,7 @@

var/ret = call_ext("byondapi_test.dll", "byond:test_list_index")(L)

if(ret != 4)
if(ret != 3)
throw EXCEPTION("List index access failed [json_encode(ret)]")

/test/proc/test_list_pop()
Expand Down
67 changes: 15 additions & 52 deletions crates/byondapi-rs-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![allow(clippy::missing_safety_doc)]

use byondapi::{
list::ByondValueList,
map::{byond_block, byond_length, ByondXYZ},
parse_args,
typecheck_trait::ByondTypeCheck,
Expand Down Expand Up @@ -34,20 +33,7 @@ pub unsafe extern "C" fn test_args(argc: byondapi_sys::u4c, argv: *mut ByondValu
setup_panic_handler();
let args = parse_args(argc, argv);
assert_eq!(args.len(), 1);
args[0].clone()
}

#[no_mangle]
pub unsafe extern "C" fn send_test(_argc: byondapi_sys::u4c, _argv: *mut ByondValue) -> ByondValue {
setup_panic_handler();
// let args = parse_args(argc, argv);
let new_value = ByondValue::new_str("Meow").unwrap();

std::thread::spawn(move || {
std::mem::drop(new_value);
});

ByondValue::null()
args[0]
}

#[no_mangle]
Expand Down Expand Up @@ -107,7 +93,6 @@ pub unsafe extern "C" fn test_readwrite_var(
Err(e) => format!("{:#?}", e).try_into().unwrap(),
}
}

#[no_mangle]
pub unsafe extern "C" fn test_list_push(
argc: byondapi_sys::u4c,
Expand All @@ -116,12 +101,9 @@ pub unsafe extern "C" fn test_list_push(
setup_panic_handler();
let args = parse_args(argc, argv);

let mut list: ByondValueList = match (&args[0]).try_into() {
Ok(list) => list,
Err(e) => return format!("{:#?}", e).try_into().unwrap(),
};
let mut list = args[0];

match list.push(&ByondValue::new_num(8.0)) {
match list.push_list(ByondValue::new_num(8.0)) {
Ok(_) => {}
Err(e) => return format!("{:#?}", e).try_into().unwrap(),
};
Expand All @@ -137,19 +119,15 @@ pub unsafe extern "C" fn test_list_double(
setup_panic_handler();
let args = parse_args(argc, argv);

let list: ByondValueList = match (&args[0]).try_into() {
Ok(list) => list,
Err(e) => return format!("{:#?}", e).try_into().unwrap(),
};
let list = args[0];

let collection: Vec<ByondValue> = list
.iter()
.map(|f| (f.get_number().unwrap() * 2.).try_into().unwrap())
.unwrap()
.map(|(v, _)| (v.get_number().unwrap() * 2.).try_into().unwrap())
.collect();

let list: ByondValueList = collection.as_slice().try_into().unwrap();

list.try_into().unwrap()
collection.as_slice().try_into().unwrap()
}

#[no_mangle]
Expand All @@ -160,12 +138,9 @@ pub unsafe extern "C" fn test_list_index(
setup_panic_handler();
let args = parse_args(argc, argv);

let list: ByondValueList = match (&args[0]).try_into() {
Ok(list) => list,
Err(e) => return format!("{:#?}", e).try_into().unwrap(),
};
let list = args[0];

list[3].clone()
list.read_list_index(3.0).unwrap()
}

#[no_mangle]
Expand All @@ -176,23 +151,20 @@ pub unsafe extern "C" fn test_list_pop(
setup_panic_handler();
let args = parse_args(argc, argv);

let mut list: ByondValueList = match (&args[0]).try_into() {
Ok(list) => list,
Err(e) => return format!("{:#?}", e).try_into().unwrap(),
};
let mut list = args[0];

let element = match list.pop() {
let element = match list.pop_list() {
Ok(x) => x,
Err(e) => return format!("{:#?}", e).try_into().unwrap(),
};

if list.0.count != 4 {
if list.builtin_length().unwrap().get_number().unwrap() as u32 != 4 {
return "pop did not actually remove item from list"
.try_into()
.unwrap();
}

element
element.unwrap()
}

#[no_mangle]
Expand All @@ -203,22 +175,13 @@ pub unsafe extern "C" fn test_length_with_list(
setup_panic_handler();
let args = parse_args(argc, argv);

let list: ByondValueList = match (&args[0]).try_into() {
Ok(list) => list,
Err(e) => return format!("{:#?}", e).try_into().unwrap(),
};
let list = args[0];

let value: ByondValue = match list.try_into() {
Ok(x) => x,
Err(e) => return format!("{:#?}", e).try_into().unwrap(),
};

match byond_length(&value) {
match list.builtin_length() {
Ok(x) => x,
Err(e) => format!("{:#?}", e).try_into().unwrap(),
}
}

#[no_mangle]
pub unsafe extern "C" fn test_block(argc: byondapi_sys::u4c, argv: *mut ByondValue) -> ByondValue {
setup_panic_handler();
Expand Down
8 changes: 3 additions & 5 deletions crates/byondapi-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ byondapi-sys = { path = "../byondapi-sys", version = "0.10.1" }
lazy_static = "1.4.0"
libloading = "0.8.1"
walkdir = "2.4.0"
inventory = "0.3.12"
inventory = "0.3.13"

[features]
default = ["byond-515-1611"]
byond-515-1611 = []
byond-515-1610 = []
byond-515-1609 = []
default = ["byond-515-1620"]
byond-515-1620 = []
3 changes: 3 additions & 0 deletions crates/byondapi-rs/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub enum Error {
/// Thrown by [`crate::byond_string::str_id_of_cstr`] when the string doesn't exist in
/// byondland
NonExistentString,
/// Thrown when we know byondland failed to create a string
UnableToCreateString,
}

impl Error {
Expand Down Expand Up @@ -60,6 +62,7 @@ impl std::fmt::Display for Error {
Self::NotANum => write!(f, "Value is not a number"),
Self::NotAPtr => write!(f, "Value is not a pointer"),
Self::NonExistentString => write!(f, "String id not found"),
Self::UnableToCreateString => write!(f, "Unable to create string"),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/byondapi-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub use inventory;

#[macro_use]
pub mod error;
#[cfg(feature = "byond-515-1611")]
pub mod map;
pub use error::Error;

Expand Down
Loading

0 comments on commit 8430ae1

Please sign in to comment.