Skip to content

Commit

Permalink
fuck
Browse files Browse the repository at this point in the history
  • Loading branch information
jupyterkat committed Mar 7, 2024
1 parent 5308766 commit 987bc03
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion crates/byondapi-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "byondapi-macros"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
description = "Macros for byondapi"
license = "MIT"
Expand Down
8 changes: 4 additions & 4 deletions crates/byondapi-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ pub fn bind(attr: TokenStream, item: TokenStream) -> TokenStream {
match #func_name(#proc_arg_unpacker) {
Ok(val) => val,
Err(e) => {
let error_string = ::byondapi::value::ByondValue::try_from(e.0).unwrap();
let error_string = ::byondapi::value::ByondValue::try_from(::std::format!("{e:?}")).unwrap();
::byondapi::global_call::call_global_id(byond_string!("stack_trace"), &[error_string]).unwrap();
::byondapi::value::ByondValue::null()
}
}

}
fn #func_name(#args) -> Result<::byondapi::value::ByondValue, ::byondapi::BindError>
fn #func_name(#args) -> Result<::byondapi::value::ByondValue, ::byondapi::Error>
#body
};
result.into()
Expand Down Expand Up @@ -231,13 +231,13 @@ pub fn bind_raw_args(attr: TokenStream, item: TokenStream) -> TokenStream {
match #func_name(args) {
Ok(val) => val,
Err(e) => {
let error_string = ::byondapi::value::ByondValue::try_from(e.0).unwrap();
let error_string = ::byondapi::value::ByondValue::try_from(::std::format!("{e:?}")).unwrap();
::byondapi::global_call::call_global_id(byond_string!("stack_trace"), &[error_string]).unwrap();
::byondapi::value::ByondValue::null()
}
}
}
fn #func_name(args: &mut [::byondapi::value::ByondValue]) -> Result<::byondapi::value::ByondValue, ::byondapi::BindError>
fn #func_name(args: &mut [::byondapi::value::ByondValue]) -> Result<::byondapi::value::ByondValue, ::byondapi::Error>
#body
};
result.into()
Expand Down
9 changes: 7 additions & 2 deletions crates/byondapi-rs-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ fn test_list_pop(mut list: ByondValue) {
let element = list.pop_list()?;

if list.builtin_length()?.get_number()? as u32 != 4 {
return Err(eyre::eyre!("pop did not actually remove item from list").into());
return Err(byondapi::Error::BindError(format!(
"pop did not actually remove item from list"
)));
}

Ok(element.unwrap())
Expand All @@ -113,7 +115,10 @@ fn test_block() {
)?;

if block.len() != 4 {
return Err(eyre::eyre!("block returned {} turfs when we expected 4", block.len()).into());
return Err(byondapi::Error::BindError(format!(
"block returned {} turfs when we expected 4",
block.len()
)));
}

Ok((block.len() as f32).into())
Expand Down
2 changes: 1 addition & 1 deletion crates/byondapi-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "byondapi"
version = "0.4.0"
version = "0.4.1"
authors = ["tigercat2000 <[email protected]>"]
edition = "2021"
description = "Idiomatic Rust bindings for BYONDAPI"
Expand Down
3 changes: 3 additions & 0 deletions crates/byondapi-rs/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub enum Error {
NonExistentString(CString),
/// Thrown when we know byondland failed to create a string
UnableToCreateString(CString),
/// Custom error type thrown by binds
BindError(String),
}

impl Error {
Expand Down Expand Up @@ -67,6 +69,7 @@ impl std::fmt::Display for Error {
Self::UnableToCreateString(string) => {
write!(f, "Unable to create string \"{string:#?}\"")
}
Self::BindError(string) => write!(f, "{string}"),
}
}
}
Expand Down
12 changes: 0 additions & 12 deletions crates/byondapi-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,6 @@ inventory::collect!(InitFunc);
///Or add a #[byondapi::init] attribute to a function
pub struct InitFunc(pub fn() -> ());

///Custom error type for binds, just to implement From for ?
pub struct BindError(pub String);

impl<E> From<E> for BindError
where
E: std::fmt::Debug,
{
fn from(value: E) -> Self {
BindError(format!("{value:#?}"))
}
}

///This macro caches string ids and returns it instead of doing a stringid lookup everytime
///The macro will panic if the string doesn't already exist on byond init lib
///Example usage:
Expand Down

0 comments on commit 987bc03

Please sign in to comment.