Skip to content

Commit aa8b2e2

Browse files
committed
removes type check traits, add enum for valuetype, bump version
1 parent c4e2876 commit aa8b2e2

File tree

14 files changed

+112
-131
lines changed

14 files changed

+112
-131
lines changed

crates/byondapi-rs-test/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "byondapi-test"
3-
version = "0.1.0"
3+
version = "0.0.0"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -10,6 +10,5 @@ crate-type = ["cdylib"]
1010

1111
[dependencies]
1212
byondapi = { path = "../byondapi-rs" }
13-
byondapi-sys = { path = "../byondapi-sys" }
1413
tempfile = "3.8.1"
1514
cargo_metadata = "0.18.1"

crates/byondapi-rs-test/src/lib.rs

Lines changed: 17 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#![allow(clippy::missing_safety_doc)]
22

3-
use byondapi::{
4-
byond_string,
5-
map::{byond_block, byond_length, ByondXYZ},
6-
parse_args,
7-
typecheck_trait::ByondTypeCheck,
8-
value::{pointer::ByondValuePointer, ByondValue},
9-
};
3+
use byondapi::{byond_string, map::*, parse_args, prelude::*};
104

115
#[allow(dead_code)]
126
fn write_log<T: AsRef<[u8]>>(x: T) {
@@ -21,24 +15,21 @@ fn setup_panic_handler() {
2115
}
2216

2317
#[no_mangle]
24-
pub unsafe extern "C" fn test_connection(
25-
_argc: byondapi_sys::u4c,
26-
_argv: *mut ByondValue,
27-
) -> ByondValue {
18+
pub unsafe extern "C" fn test_connection(_argc: u4c, _argv: *mut ByondValue) -> ByondValue {
2819
setup_panic_handler();
2920
ByondValue::new_num(69.0)
3021
}
3122

3223
#[no_mangle]
33-
pub unsafe extern "C" fn test_args(argc: byondapi_sys::u4c, argv: *mut ByondValue) -> ByondValue {
24+
pub unsafe extern "C" fn test_args(argc: u4c, argv: *mut ByondValue) -> ByondValue {
3425
setup_panic_handler();
3526
let args = parse_args(argc, argv);
3627
assert_eq!(args.len(), 1);
3728
args[0]
3829
}
3930

4031
#[no_mangle]
41-
pub unsafe extern "C" fn test_ptr(argc: byondapi_sys::u4c, argv: *mut ByondValue) -> ByondValue {
32+
pub unsafe extern "C" fn test_ptr(argc: u4c, argv: *mut ByondValue) -> ByondValue {
4233
setup_panic_handler();
4334
let args = parse_args(argc, argv);
4435
let pointer = match ByondValuePointer::new(args[0].clone()) {
@@ -64,10 +55,7 @@ pub unsafe extern "C" fn test_ptr(argc: byondapi_sys::u4c, argv: *mut ByondValue
6455
}
6556

6657
#[no_mangle]
67-
pub unsafe extern "C" fn test_proc_call(
68-
argc: byondapi_sys::u4c,
69-
argv: *mut ByondValue,
70-
) -> ByondValue {
58+
pub unsafe extern "C" fn test_proc_call(argc: u4c, argv: *mut ByondValue) -> ByondValue {
7159
setup_panic_handler();
7260
let args = parse_args(argc, argv);
7361

@@ -80,10 +68,7 @@ pub unsafe extern "C" fn test_proc_call(
8068
}
8169

8270
#[no_mangle]
83-
pub unsafe extern "C" fn test_readwrite_var(
84-
argc: byondapi_sys::u4c,
85-
argv: *mut ByondValue,
86-
) -> ByondValue {
71+
pub unsafe extern "C" fn test_readwrite_var(argc: u4c, argv: *mut ByondValue) -> ByondValue {
8772
setup_panic_handler();
8873
let args = parse_args(argc, argv);
8974
let object = &args[0];
@@ -100,10 +85,7 @@ pub unsafe extern "C" fn test_readwrite_var(
10085
}
10186
}
10287
#[no_mangle]
103-
pub unsafe extern "C" fn test_list_push(
104-
argc: byondapi_sys::u4c,
105-
argv: *mut ByondValue,
106-
) -> ByondValue {
88+
pub unsafe extern "C" fn test_list_push(argc: u4c, argv: *mut ByondValue) -> ByondValue {
10789
setup_panic_handler();
10890
let args = parse_args(argc, argv);
10991

@@ -118,10 +100,7 @@ pub unsafe extern "C" fn test_list_push(
118100
}
119101

120102
#[no_mangle]
121-
pub unsafe extern "C" fn test_list_double(
122-
argc: byondapi_sys::u4c,
123-
argv: *mut ByondValue,
124-
) -> ByondValue {
103+
pub unsafe extern "C" fn test_list_double(argc: u4c, argv: *mut ByondValue) -> ByondValue {
125104
setup_panic_handler();
126105
let args = parse_args(argc, argv);
127106

@@ -137,10 +116,7 @@ pub unsafe extern "C" fn test_list_double(
137116
}
138117

139118
#[no_mangle]
140-
pub unsafe extern "C" fn test_list_index(
141-
argc: byondapi_sys::u4c,
142-
argv: *mut ByondValue,
143-
) -> ByondValue {
119+
pub unsafe extern "C" fn test_list_index(argc: u4c, argv: *mut ByondValue) -> ByondValue {
144120
setup_panic_handler();
145121
let args = parse_args(argc, argv);
146122

@@ -150,10 +126,7 @@ pub unsafe extern "C" fn test_list_index(
150126
}
151127

152128
#[no_mangle]
153-
pub unsafe extern "C" fn test_list_pop(
154-
argc: byondapi_sys::u4c,
155-
argv: *mut ByondValue,
156-
) -> ByondValue {
129+
pub unsafe extern "C" fn test_list_pop(argc: u4c, argv: *mut ByondValue) -> ByondValue {
157130
setup_panic_handler();
158131
let args = parse_args(argc, argv);
159132

@@ -174,10 +147,7 @@ pub unsafe extern "C" fn test_list_pop(
174147
}
175148

176149
#[no_mangle]
177-
pub unsafe extern "C" fn test_length_with_list(
178-
argc: byondapi_sys::u4c,
179-
argv: *mut ByondValue,
180-
) -> ByondValue {
150+
pub unsafe extern "C" fn test_length_with_list(argc: u4c, argv: *mut ByondValue) -> ByondValue {
181151
setup_panic_handler();
182152
let args = parse_args(argc, argv);
183153

@@ -189,7 +159,7 @@ pub unsafe extern "C" fn test_length_with_list(
189159
}
190160
}
191161
#[no_mangle]
192-
pub unsafe extern "C" fn test_block(argc: byondapi_sys::u4c, argv: *mut ByondValue) -> ByondValue {
162+
pub unsafe extern "C" fn test_block(argc: u4c, argv: *mut ByondValue) -> ByondValue {
193163
setup_panic_handler();
194164
let _args = parse_args(argc, argv);
195165

@@ -211,10 +181,7 @@ pub unsafe extern "C" fn test_block(argc: byondapi_sys::u4c, argv: *mut ByondVal
211181
}
212182

213183
#[no_mangle]
214-
pub unsafe extern "C" fn test_length_with_str(
215-
argc: byondapi_sys::u4c,
216-
argv: *mut ByondValue,
217-
) -> ByondValue {
184+
pub unsafe extern "C" fn test_length_with_str(argc: u4c, argv: *mut ByondValue) -> ByondValue {
218185
setup_panic_handler();
219186
let args = parse_args(argc, argv);
220187

@@ -224,10 +191,7 @@ pub unsafe extern "C" fn test_length_with_str(
224191
}
225192
}
226193
#[no_mangle]
227-
pub unsafe extern "C" fn test_list_key_lookup(
228-
argc: byondapi_sys::u4c,
229-
argv: *mut ByondValue,
230-
) -> ByondValue {
194+
pub unsafe extern "C" fn test_list_key_lookup(argc: u4c, argv: *mut ByondValue) -> ByondValue {
231195
setup_panic_handler();
232196
let args = parse_args(argc, argv);
233197

@@ -278,7 +242,7 @@ pub unsafe extern "C" fn test_list_key_lookup(
278242
}
279243

280244
#[no_mangle]
281-
pub unsafe extern "C" fn test_ref(argc: byondapi_sys::u4c, argv: *mut ByondValue) -> ByondValue {
245+
pub unsafe extern "C" fn test_ref(argc: u4c, argv: *mut ByondValue) -> ByondValue {
282246
setup_panic_handler();
283247
let args = parse_args(argc, argv);
284248

@@ -290,10 +254,7 @@ pub unsafe extern "C" fn test_ref(argc: byondapi_sys::u4c, argv: *mut ByondValue
290254
}
291255

292256
#[no_mangle]
293-
pub unsafe extern "C" fn test_non_assoc_list(
294-
argc: byondapi_sys::u4c,
295-
argv: *mut ByondValue,
296-
) -> ByondValue {
257+
pub unsafe extern "C" fn test_non_assoc_list(argc: u4c, argv: *mut ByondValue) -> ByondValue {
297258
setup_panic_handler();
298259
let args = parse_args(argc, argv);
299260
let list = args.get(0).unwrap();
@@ -318,10 +279,7 @@ pub unsafe extern "C" fn test_non_assoc_list(
318279
}
319280

320281
#[no_mangle]
321-
pub unsafe extern "C" fn test_list_read(
322-
argc: byondapi_sys::u4c,
323-
argv: *mut ByondValue,
324-
) -> ByondValue {
282+
pub unsafe extern "C" fn test_list_read(argc: u4c, argv: *mut ByondValue) -> ByondValue {
325283
setup_panic_handler();
326284
let args = parse_args(argc, argv);
327285
let list = args.get(0).unwrap();

crates/byondapi-rs/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "byondapi"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
authors = ["tigercat2000 <[email protected]>"]
55
edition = "2021"
66
description = "Idiomatic Rust bindings for BYONDAPI"
@@ -13,7 +13,7 @@ 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.0" }
16+
byondapi-sys = { path = "../byondapi-sys" }
1717
lazy_static = "1.4.0"
1818
libloading = "0.8.1"
1919
walkdir = "2.4.0"

crates/byondapi-rs/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub use error::Error;
1111
pub mod byond_string;
1212
pub mod global_call;
1313
pub mod prelude;
14-
pub mod typecheck_trait;
1514
pub mod value;
1615

1716
use crate::value::ByondValue;

crates/byondapi-rs/src/prelude.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,11 @@ pub use crate::sys::s2cMIN;
1414
pub use crate::sys::s4c;
1515
pub use crate::sys::s4cMAX;
1616
pub use crate::sys::s4cMIN;
17+
pub use crate::sys::s8c;
1718
pub use crate::sys::u1c;
18-
// pub use crate::sys::u1cMAX;
19-
// pub use crate::sys::u1cMIN;
2019
pub use crate::sys::u2c;
21-
// pub use crate::sys::u2cMAX;
22-
// pub use crate::sys::u2cMIN;
2320
pub use crate::sys::u4c;
24-
// pub use crate::sys::u4cMAX;
25-
// pub use crate::sys::u4cMIN;
2621
pub use crate::sys::u8c;
27-
// pub use crate::sys::u8cMAX;
28-
// pub use crate::sys::u8cMIN;
29-
pub use crate::sys::s8c;
30-
// pub use crate::sys::s8cMAX;
31-
// pub use crate::sys::s8cMIN;
3222

3323
// Other types
3424
pub use byondapi_sys::u4cOrPointer;
@@ -38,4 +28,6 @@ pub use byondapi_sys::CByondValue as InternalByondValue;
3828

3929
// As well as our own types.
4030
pub use crate::byond_string;
31+
pub use crate::value::pointer::ByondValuePointer;
32+
pub use crate::value::types::ValueType;
4133
pub use crate::value::ByondValue;

crates/byondapi-rs/src/static_global.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn init_lib() -> byondapi_sys::ByondApi {
1010
Ok(lib) => lib,
1111
Err(e) => {
1212
let message = format!(
13-
"byondcore.dll is not loaded into the process as expected: {:#?}",
13+
"byondcore is not loaded into the process as expected: {:#?}",
1414
e
1515
);
1616
crate::error::crash_logging::log_to_file(&message);
@@ -32,7 +32,7 @@ fn init_lib() -> byondapi_sys::ByondApi {
3232
match unsafe { byondapi_sys::ByondApi::init_from_library(library) } {
3333
Err(e) => {
3434
let message = format!(
35-
"byondcore.dll is not loaded into the process as expected: {:#?}",
35+
"byondcore is not loaded into the process as expected: {:#?}",
3636
e
3737
);
3838
crate::error::crash_logging::log_to_file(&message);
@@ -42,6 +42,8 @@ fn init_lib() -> byondapi_sys::ByondApi {
4242
}
4343
}
4444

45+
///Initialises the byond lib, and calls relevant init functions defined by inventory.
46+
///Or returns a reference to the lib if already initialised.
4547
#[inline(always)]
4648
pub fn byond() -> &'static byondapi_sys::ByondApi {
4749
BYOND.get_or_init(init_lib)

crates/byondapi-rs/src/typecheck_trait.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

crates/byondapi-rs/src/value/constructors.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::ffi::CString;
22

3-
use byondapi_sys::{u4c, ByondValueType, CByondValue};
3+
use byondapi_sys::{u4c, CByondValue};
44

5-
use super::ByondValue;
5+
use super::{types::ValueType, ByondValue};
66
use crate::{static_global::byond, Error};
77

88
impl Default for ByondValue {
@@ -19,17 +19,17 @@ impl ByondValue {
1919

2020
pub fn null() -> Self {
2121
Self(CByondValue {
22-
type_: 0,
22+
type_: ValueType::Null as u8,
2323
junk1: 0,
2424
junk2: 0,
2525
junk3: 0,
2626
data: byondapi_sys::ByondValueData { ref_: 0 },
2727
})
2828
}
2929

30-
pub fn new_ref(typ: ByondValueType, ptr: u4c) -> Self {
30+
pub fn new_ref(typ: ValueType, ptr: u4c) -> Self {
3131
Self(CByondValue {
32-
type_: typ,
32+
type_: typ as u8,
3333
junk1: 0,
3434
junk2: 0,
3535
junk3: 0,
@@ -39,7 +39,7 @@ impl ByondValue {
3939

4040
pub fn new_num(f: f32) -> Self {
4141
Self(CByondValue {
42-
type_: 0x2A,
42+
type_: ValueType::Number as u8,
4343
junk1: 0,
4444
junk2: 0,
4545
junk3: 0,
@@ -49,7 +49,7 @@ impl ByondValue {
4949

5050
pub fn new_global_ref() -> Self {
5151
Self(CByondValue {
52-
type_: 0x0E,
52+
type_: ValueType::World as u8,
5353
junk1: 0,
5454
junk2: 0,
5555
junk3: 0,
@@ -64,7 +64,7 @@ impl ByondValue {
6464
return Err(Error::UnableToCreateString);
6565
}
6666
Ok(Self(CByondValue {
67-
type_: 0x06,
67+
type_: ValueType::String as u8,
6868
junk1: 0,
6969
junk2: 0,
7070
junk3: 0,
@@ -80,11 +80,3 @@ impl ByondValue {
8080
Ok(new_self)
8181
}
8282
}
83-
84-
impl<'a> ByondValue {
85-
/// # Safety
86-
/// The [`CByondValue`] must be initialized.
87-
pub unsafe fn from_ref(s: &'a CByondValue) -> &'a Self {
88-
unsafe { std::mem::transmute(s) }
89-
}
90-
}

crates/byondapi-rs/src/value/functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ffi::CString;
33
use byondapi_sys::{u4c, ByondValueType, CByondValue};
44

55
use super::ByondValue;
6-
use crate::{map::byond_length, static_global::byond, typecheck_trait::ByondTypeCheck, Error};
6+
use crate::{map::byond_length, static_global::byond, Error};
77

88
/// # Compatibility with the C++ API
99
impl ByondValue {

crates/byondapi-rs/src/value/list.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::{
2-
byond_string_internal, static_global::byond, typecheck_trait::ByondTypeCheck,
3-
value::ByondValue, Error,
4-
};
1+
use crate::{byond_string_internal, static_global::byond, value::ByondValue, Error};
52
/// List stuff goes here, Keep in mind that all indexing method starts at zero instead of one like byondland
63
impl ByondValue {
74
/// Gets an array of all the list elements, this means keys for assoc lists and values for regular lists

0 commit comments

Comments
 (0)