Skip to content

Commit b2592d0

Browse files
committed
initial 516
1 parent c3b15e8 commit b2592d0

File tree

20 files changed

+792
-67
lines changed

20 files changed

+792
-67
lines changed

crates/byondapi-macros/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "byondapi-macros"
3-
version = "0.1.3"
3+
version = "0.2.3"
44
edition = "2021"
55
description = "Macros for byondapi"
66
license = "MIT"
@@ -17,3 +17,6 @@ proc-macro2 = "1.0"
1717
[dependencies.syn]
1818
version = "2.0"
1919
features = ["full", "parsing", "printing"]
20+
21+
[features]
22+
old-crash-workaround = []

crates/byondapi-macros/src/lib.rs

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,32 @@ pub fn bind(attr: TokenStream, item: TokenStream) -> TokenStream {
159159
}
160160
};
161161

162+
let crash_syntax = if cfg!(feature = "old-crash-workaround") {
163+
quote! {
164+
let error_string = ::byondapi::value::ByondValue::try_from(error_string).unwrap();
165+
::byondapi::global_call::call_global_id({
166+
static STACK_TRACE: ::std::sync::OnceLock<u32> = ::std::sync::OnceLock::new();
167+
*STACK_TRACE.get_or_init(|| ::byondapi::byond_string::str_id_of("byondapi_stack_trace")
168+
.expect("byondapi-rs implicitly expects byondapi_stack_trace to exist as a proc for error reporting purposes, this proc doesn't exist!")
169+
)
170+
}
171+
,&[error_string]).unwrap();
172+
}
173+
} else {
174+
quote! {
175+
::byondapi::runtime::byond_runtime(error_string);
176+
}
177+
};
178+
162179
let result = quote! {
163180
#cthook_prelude
164181
#signature {
165182
let args = unsafe { ::byondapi::parse_args(__argc, __argv) };
166183
match #func_name(#proc_arg_unpacker) {
167184
Ok(val) => val,
168185
Err(e) => {
169-
let error_string = ::byondapi::value::ByondValue::try_from(::std::format!("{e:?}")).unwrap();
170-
::byondapi::global_call::call_global_id({
171-
static STACK_TRACE: ::std::sync::OnceLock<u32> = ::std::sync::OnceLock::new();
172-
*STACK_TRACE.get_or_init(|| ::byondapi::byond_string::str_id_of("byondapi_stack_trace")
173-
.expect("byondapi-rs implicitly expects byondapi_stack_trace to exist as a proc for error reporting purposes, this proc doesn't exist!")
174-
)
175-
}
176-
,&[error_string]).unwrap();
186+
let error_string = ::std::format!("{e:?}");
187+
#crash_syntax
177188
::byondapi::value::ByondValue::null()
178189
}
179190
}
@@ -303,6 +314,22 @@ pub fn bind_raw_args(attr: TokenStream, item: TokenStream) -> TokenStream {
303314
}
304315
}
305316
};
317+
let crash_syntax = if cfg!(feature = "old-crash-workaround") {
318+
quote! {
319+
let error_string = ::byondapi::value::ByondValue::try_from(error_string).unwrap();
320+
::byondapi::global_call::call_global_id({
321+
static STACK_TRACE: ::std::sync::OnceLock<u32> = ::std::sync::OnceLock::new();
322+
*STACK_TRACE.get_or_init(|| ::byondapi::byond_string::str_id_of("byondapi_stack_trace")
323+
.expect("byondapi-rs implicitly expects byondapi_stack_trace to exist as a proc for error reporting purposes, this proc doesn't exist!")
324+
)
325+
}
326+
,&[error_string]).unwrap();
327+
}
328+
} else {
329+
quote! {
330+
::byondapi::runtime::byond_runtime(error_string);
331+
}
332+
};
306333

307334
let result = quote! {
308335
#cthook_prelude
@@ -311,14 +338,8 @@ pub fn bind_raw_args(attr: TokenStream, item: TokenStream) -> TokenStream {
311338
match #func_name(args) {
312339
Ok(val) => val,
313340
Err(e) => {
314-
let error_string = ::byondapi::value::ByondValue::try_from(::std::format!("{e:?}")).unwrap();
315-
::byondapi::global_call::call_global_id({
316-
static STACK_TRACE: ::std::sync::OnceLock<u32> = ::std::sync::OnceLock::new();
317-
*STACK_TRACE.get_or_init(|| ::byondapi::byond_string::str_id_of("byondapi_stack_trace")
318-
.expect("byondapi-rs implicitly expects byondapi_stack_trace to exist as a proc for error reporting purposes, this proc doesn't exist!")
319-
)
320-
}
321-
,&[error_string]).unwrap();
341+
let error_string = ::std::format!("{e:?}");
342+
#crash_syntax
322343
::byondapi::value::ByondValue::null()
323344
}
324345
}

crates/byondapi-rs-test/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ crate-type = ["cdylib"]
1010

1111
[dependencies]
1212
byondapi = { path = "../byondapi-rs" }
13-
tempfile = "3.13.0"
14-
cargo_metadata = "0.18.1"
13+
tempfile = "3.14.0"
14+
cargo_metadata = "0.19.1"
1515
eyre = "0.6.12"

crates/byondapi-rs-test/dm_project/bindings.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
return __byondapi_test = "byondapi_test"
1111

1212
#define BYONDAPI_TEST (__byondapi_test || __detect_byondapi_test())
13-
13+
1414
///Tests new
1515
/proc/test_new_obj()
1616
return call_ext(BYONDAPI_TEST, "byond:test_new_obj_ffi")()

crates/byondapi-rs-test/dm_project/dm_project.dme

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#include "test_map.dmm"
22
#include "bindings.dm"
33

4-
/proc/byondapi_stack_trace(msg)
5-
CRASH(msg)
6-
74
/turf/turf_type_a
85
color = "#FF0000"
96
/turf/turf_type_b

crates/byondapi-rs/Cargo.toml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "byondapi"
3-
version = "0.4.11"
3+
version = "0.5.11"
44
authors = ["tigercat2000 <[email protected]>"]
55
edition = "2021"
66
description = "Idiomatic Rust bindings for BYONDAPI"
@@ -13,12 +13,16 @@ exclude = [".vscode/*"]
1313
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1414

1515
[dependencies]
16-
byondapi-sys = { path = "../byondapi-sys", version = "0.11.2" }
17-
byondapi-macros = { path = "../byondapi-macros", version = "0.1.3" }
18-
libloading = "0.8.5"
19-
inventory = "0.3.15"
16+
byondapi-sys = { path = "../byondapi-sys", version = "0.12.2", default-features = false }
17+
byondapi-macros = { path = "../byondapi-macros", version = "0.2.3" }
18+
libloading = "0.8.6"
19+
inventory = "0.3.16"
2020
num_enum = "0.7.3"
2121

2222
[features]
23-
default = ["byond-515-1621"]
24-
byond-515-1621 = []
23+
default = ["byond-516-1648"]
24+
byond-515-1621 = [
25+
"byondapi-macros/old-crash-workaround",
26+
"byondapi-sys/byond-515-1621",
27+
]
28+
byond-516-1648 = ["byondapi-sys/byond-516-1648"]

crates/byondapi-rs/src/binds.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ pub fn generate_bindings(libname: &str) {
1414
_ = std::fs::remove_file("./bindings.dm");
1515
let mut file = std::fs::File::create("./bindings.dm").unwrap();
1616
let libname_upper = libname.to_uppercase();
17+
18+
let byond_compat_crash = {
19+
if cfg!(feature = "byond-515-1621") {
20+
"
21+
/proc/byondapi_stack_trace(msg)
22+
CRASH(msg)"
23+
} else {
24+
""
25+
}
26+
};
1727
file.write_fmt(format_args!(
1828
"//THIS FILE IS AUTOMATICALLY GENERATED BY {libname_upper}, PLEASE DO NOT TOUCH IT
1929
//PROC DEFINITIONS MAY MOVE AROUND, THIS IS NORMAL
@@ -27,10 +37,7 @@ pub fn generate_bindings(libname: &str) {
2737
return __{libname} = \"{libname}\"
2838
2939
#define {libname_upper} (__{libname} || __detect_{libname}())
30-
31-
/proc/byondapi_stack_trace(msg)
32-
CRASH(msg)
33-
40+
{byond_compat_crash}
3441
"
3542
))
3643
.unwrap();

crates/byondapi-rs/src/global_call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn call_global<T: Into<Vec<u8>>>(name: T, args: &[ByondValue]) -> Result<Byo
1616
return Err(Error::InvalidProc(c_string));
1717
}
1818
let ptr = args.as_ptr();
19-
let mut new_value = ByondValue::new();
19+
let mut new_value = ByondValue::default();
2020
unsafe {
2121
map_byond_error!(byond().Byond_CallGlobalProcByStrId(
2222
str_id,
@@ -33,7 +33,7 @@ pub fn call_global<T: Into<Vec<u8>>>(name: T, args: &[ByondValue]) -> Result<Byo
3333
/// Implicitly set waitfor=0, will never block.
3434
pub fn call_global_id(name: u4c, args: &[ByondValue]) -> Result<ByondValue, Error> {
3535
let ptr = args.as_ptr();
36-
let mut new_value = ByondValue::new();
36+
let mut new_value = ByondValue::default();
3737
unsafe {
3838
map_byond_error!(byond().Byond_CallGlobalProcByStrId(
3939
name,

crates/byondapi-rs/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ pub use inventory;
1313
#[macro_use]
1414
pub mod error;
1515
pub mod map;
16+
#[cfg(feature = "byond-516-1648")]
17+
pub mod pixloc;
18+
#[cfg(feature = "byond-516-1648")]
19+
pub mod runtime;
1620
pub use error::Error;
1721

1822
pub mod binds;

crates/byondapi-rs/src/map.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ use crate::{prelude::ByondValue, static_global::byond, Error};
88
pub struct ByondXYZ(CByondXYZ);
99

1010
impl ByondXYZ {
11-
pub fn new() -> Self {
12-
Self(CByondXYZ {
13-
x: 0,
14-
y: 0,
15-
z: 0,
16-
junk: 0,
17-
})
18-
}
19-
2011
pub fn with_coords((x, y, z): (i16, i16, i16)) -> Self {
2112
Self(CByondXYZ { x, y, z, junk: 0 })
2213
}
@@ -27,7 +18,12 @@ impl ByondXYZ {
2718

2819
impl Default for ByondXYZ {
2920
fn default() -> Self {
30-
Self::new()
21+
Self(CByondXYZ {
22+
x: 0,
23+
y: 0,
24+
z: 0,
25+
junk: 0,
26+
})
3127
}
3228
}
3329

@@ -76,7 +72,7 @@ pub fn byond_block(corner1: ByondXYZ, corner2: ByondXYZ) -> Result<Vec<ByondValu
7672
/// Corresponds to the first variation of [`dm::locate(Type) in Container`](https://www.byond.com/docs/ref/#/proc/locate)
7773
/// Finds an object prototype or tag within the haystack, usually used for finding objects within a turf/area/etc
7874
pub fn byond_locatein(needle: &ByondValue, haystack: &ByondValue) -> Result<ByondValue, Error> {
79-
let mut output = ByondValue::new();
75+
let mut output = ByondValue::default();
8076

8177
// Safety: needle, haystack, and output must be initialized, we take care of this.
8278
unsafe { map_byond_error!(byond().Byond_LocateIn(&needle.0, &haystack.0, &mut output.0))? };
@@ -87,7 +83,7 @@ pub fn byond_locatein(needle: &ByondValue, haystack: &ByondValue) -> Result<Byon
8783
/// Corresponds to the third and forth variation of [`dm::locate(Tag/TextRef)`](https://www.byond.com/docs/ref/#/proc/locate)
8884
/// Finds an object prototype or tag within the world.
8985
pub fn byond_locateby(target: &ByondValue) -> Result<ByondValue, Error> {
90-
let mut output = ByondValue::new();
86+
let mut output = ByondValue::default();
9187

9288
// Safety: target and output must be initialized, we take care of this.
9389
unsafe {
@@ -100,7 +96,7 @@ pub fn byond_locateby(target: &ByondValue) -> Result<ByondValue, Error> {
10096
/// Corresponds to the second variation of [`dm::locate(X,Y,Z)`](https://www.byond.com/docs/ref/#/proc/locate)
10197
/// Finds a turf at the given coordinates.
10298
pub fn byond_locatexyz(coords: ByondXYZ) -> Result<ByondValue, Error> {
103-
let mut output = ByondValue::new();
99+
let mut output = ByondValue::default();
104100

105101
// Safety: coords and output must be initialized, we take care of this.
106102
unsafe { map_byond_error!(byond().Byond_LocateXYZ(&coords.0, &mut output.0))? };
@@ -111,7 +107,7 @@ pub fn byond_locatexyz(coords: ByondXYZ) -> Result<ByondValue, Error> {
111107
/// Corresponds to accessing [`atom.loc`](https://www.byond.com/docs/ref/#/atom/var/loc)
112108
/// Gets the location of the target, which will be 0,0,0 if the atom is not directly on a turf.
113109
pub fn byond_xyz(target: &ByondValue) -> Result<ByondXYZ, Error> {
114-
let mut output = ByondXYZ::new();
110+
let mut output = ByondXYZ::default();
115111

116112
// Safety: target and output must be initialized, we take care of this.
117113
unsafe { map_byond_error!(byond().Byond_XYZ(&target.0, &mut output.0))? };

0 commit comments

Comments
 (0)