Skip to content

Commit

Permalink
removes type check traits, add enum for valuetype, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
jupyterkat committed Dec 14, 2023
1 parent c4e2876 commit aa8b2e2
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 131 deletions.
3 changes: 1 addition & 2 deletions crates/byondapi-rs-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "byondapi-test"
version = "0.1.0"
version = "0.0.0"
edition = "2021"

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

[dependencies]
byondapi = { path = "../byondapi-rs" }
byondapi-sys = { path = "../byondapi-sys" }
tempfile = "3.8.1"
cargo_metadata = "0.18.1"
76 changes: 17 additions & 59 deletions crates/byondapi-rs-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#![allow(clippy::missing_safety_doc)]

use byondapi::{
byond_string,
map::{byond_block, byond_length, ByondXYZ},
parse_args,
typecheck_trait::ByondTypeCheck,
value::{pointer::ByondValuePointer, ByondValue},
};
use byondapi::{byond_string, map::*, parse_args, prelude::*};

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

#[no_mangle]
pub unsafe extern "C" fn test_connection(
_argc: byondapi_sys::u4c,
_argv: *mut ByondValue,
) -> ByondValue {
pub unsafe extern "C" fn test_connection(_argc: u4c, _argv: *mut ByondValue) -> ByondValue {
setup_panic_handler();
ByondValue::new_num(69.0)
}

#[no_mangle]
pub unsafe extern "C" fn test_args(argc: byondapi_sys::u4c, argv: *mut ByondValue) -> ByondValue {
pub unsafe extern "C" fn test_args(argc: u4c, argv: *mut ByondValue) -> ByondValue {
setup_panic_handler();
let args = parse_args(argc, argv);
assert_eq!(args.len(), 1);
args[0]
}

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

#[no_mangle]
pub unsafe extern "C" fn test_proc_call(
argc: byondapi_sys::u4c,
argv: *mut ByondValue,
) -> ByondValue {
pub unsafe extern "C" fn test_proc_call(argc: u4c, argv: *mut ByondValue) -> ByondValue {
setup_panic_handler();
let args = parse_args(argc, argv);

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

#[no_mangle]
pub unsafe extern "C" fn test_readwrite_var(
argc: byondapi_sys::u4c,
argv: *mut ByondValue,
) -> ByondValue {
pub unsafe extern "C" fn test_readwrite_var(argc: u4c, argv: *mut ByondValue) -> ByondValue {
setup_panic_handler();
let args = parse_args(argc, argv);
let object = &args[0];
Expand All @@ -100,10 +85,7 @@ pub unsafe extern "C" fn test_readwrite_var(
}
}
#[no_mangle]
pub unsafe extern "C" fn test_list_push(
argc: byondapi_sys::u4c,
argv: *mut ByondValue,
) -> ByondValue {
pub unsafe extern "C" fn test_list_push(argc: u4c, argv: *mut ByondValue) -> ByondValue {
setup_panic_handler();
let args = parse_args(argc, argv);

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

#[no_mangle]
pub unsafe extern "C" fn test_list_double(
argc: byondapi_sys::u4c,
argv: *mut ByondValue,
) -> ByondValue {
pub unsafe extern "C" fn test_list_double(argc: u4c, argv: *mut ByondValue) -> ByondValue {
setup_panic_handler();
let args = parse_args(argc, argv);

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

#[no_mangle]
pub unsafe extern "C" fn test_list_index(
argc: byondapi_sys::u4c,
argv: *mut ByondValue,
) -> ByondValue {
pub unsafe extern "C" fn test_list_index(argc: u4c, argv: *mut ByondValue) -> ByondValue {
setup_panic_handler();
let args = parse_args(argc, argv);

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

#[no_mangle]
pub unsafe extern "C" fn test_list_pop(
argc: byondapi_sys::u4c,
argv: *mut ByondValue,
) -> ByondValue {
pub unsafe extern "C" fn test_list_pop(argc: u4c, argv: *mut ByondValue) -> ByondValue {
setup_panic_handler();
let args = parse_args(argc, argv);

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

#[no_mangle]
pub unsafe extern "C" fn test_length_with_list(
argc: byondapi_sys::u4c,
argv: *mut ByondValue,
) -> ByondValue {
pub unsafe extern "C" fn test_length_with_list(argc: u4c, argv: *mut ByondValue) -> ByondValue {
setup_panic_handler();
let args = parse_args(argc, argv);

Expand All @@ -189,7 +159,7 @@ pub unsafe extern "C" fn test_length_with_list(
}
}
#[no_mangle]
pub unsafe extern "C" fn test_block(argc: byondapi_sys::u4c, argv: *mut ByondValue) -> ByondValue {
pub unsafe extern "C" fn test_block(argc: u4c, argv: *mut ByondValue) -> ByondValue {
setup_panic_handler();
let _args = parse_args(argc, argv);

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

#[no_mangle]
pub unsafe extern "C" fn test_length_with_str(
argc: byondapi_sys::u4c,
argv: *mut ByondValue,
) -> ByondValue {
pub unsafe extern "C" fn test_length_with_str(argc: u4c, argv: *mut ByondValue) -> ByondValue {
setup_panic_handler();
let args = parse_args(argc, argv);

Expand All @@ -224,10 +191,7 @@ pub unsafe extern "C" fn test_length_with_str(
}
}
#[no_mangle]
pub unsafe extern "C" fn test_list_key_lookup(
argc: byondapi_sys::u4c,
argv: *mut ByondValue,
) -> ByondValue {
pub unsafe extern "C" fn test_list_key_lookup(argc: u4c, argv: *mut ByondValue) -> ByondValue {
setup_panic_handler();
let args = parse_args(argc, argv);

Expand Down Expand Up @@ -278,7 +242,7 @@ pub unsafe extern "C" fn test_list_key_lookup(
}

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

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

#[no_mangle]
pub unsafe extern "C" fn test_non_assoc_list(
argc: byondapi_sys::u4c,
argv: *mut ByondValue,
) -> ByondValue {
pub unsafe extern "C" fn test_non_assoc_list(argc: u4c, argv: *mut ByondValue) -> ByondValue {
setup_panic_handler();
let args = parse_args(argc, argv);
let list = args.get(0).unwrap();
Expand All @@ -318,10 +279,7 @@ pub unsafe extern "C" fn test_non_assoc_list(
}

#[no_mangle]
pub unsafe extern "C" fn test_list_read(
argc: byondapi_sys::u4c,
argv: *mut ByondValue,
) -> ByondValue {
pub unsafe extern "C" fn test_list_read(argc: u4c, argv: *mut ByondValue) -> ByondValue {
setup_panic_handler();
let args = parse_args(argc, argv);
let list = args.get(0).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions crates/byondapi-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "byondapi"
version = "0.3.0"
version = "0.3.1"
authors = ["tigercat2000 <[email protected]>"]
edition = "2021"
description = "Idiomatic Rust bindings for BYONDAPI"
Expand All @@ -13,7 +13,7 @@ exclude = [".vscode/*"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
byondapi-sys = { path = "../byondapi-sys", version = "0.11.0" }
byondapi-sys = { path = "../byondapi-sys" }
lazy_static = "1.4.0"
libloading = "0.8.1"
walkdir = "2.4.0"
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 @@ -11,7 +11,6 @@ pub use error::Error;
pub mod byond_string;
pub mod global_call;
pub mod prelude;
pub mod typecheck_trait;
pub mod value;

use crate::value::ByondValue;
Expand Down
14 changes: 3 additions & 11 deletions crates/byondapi-rs/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,11 @@ pub use crate::sys::s2cMIN;
pub use crate::sys::s4c;
pub use crate::sys::s4cMAX;
pub use crate::sys::s4cMIN;
pub use crate::sys::s8c;
pub use crate::sys::u1c;
// pub use crate::sys::u1cMAX;
// pub use crate::sys::u1cMIN;
pub use crate::sys::u2c;
// pub use crate::sys::u2cMAX;
// pub use crate::sys::u2cMIN;
pub use crate::sys::u4c;
// pub use crate::sys::u4cMAX;
// pub use crate::sys::u4cMIN;
pub use crate::sys::u8c;
// pub use crate::sys::u8cMAX;
// pub use crate::sys::u8cMIN;
pub use crate::sys::s8c;
// pub use crate::sys::s8cMAX;
// pub use crate::sys::s8cMIN;

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

// As well as our own types.
pub use crate::byond_string;
pub use crate::value::pointer::ByondValuePointer;
pub use crate::value::types::ValueType;
pub use crate::value::ByondValue;
6 changes: 4 additions & 2 deletions crates/byondapi-rs/src/static_global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn init_lib() -> byondapi_sys::ByondApi {
Ok(lib) => lib,
Err(e) => {
let message = format!(
"byondcore.dll is not loaded into the process as expected: {:#?}",
"byondcore is not loaded into the process as expected: {:#?}",
e
);
crate::error::crash_logging::log_to_file(&message);
Expand All @@ -32,7 +32,7 @@ fn init_lib() -> byondapi_sys::ByondApi {
match unsafe { byondapi_sys::ByondApi::init_from_library(library) } {
Err(e) => {
let message = format!(
"byondcore.dll is not loaded into the process as expected: {:#?}",
"byondcore is not loaded into the process as expected: {:#?}",
e
);
crate::error::crash_logging::log_to_file(&message);
Expand All @@ -42,6 +42,8 @@ fn init_lib() -> byondapi_sys::ByondApi {
}
}

///Initialises the byond lib, and calls relevant init functions defined by inventory.
///Or returns a reference to the lib if already initialised.
#[inline(always)]
pub fn byond() -> &'static byondapi_sys::ByondApi {
BYOND.get_or_init(init_lib)
Expand Down
21 changes: 0 additions & 21 deletions crates/byondapi-rs/src/typecheck_trait.rs

This file was deleted.

24 changes: 8 additions & 16 deletions crates/byondapi-rs/src/value/constructors.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::ffi::CString;

use byondapi_sys::{u4c, ByondValueType, CByondValue};
use byondapi_sys::{u4c, CByondValue};

use super::ByondValue;
use super::{types::ValueType, ByondValue};
use crate::{static_global::byond, Error};

impl Default for ByondValue {
Expand All @@ -19,17 +19,17 @@ impl ByondValue {

pub fn null() -> Self {
Self(CByondValue {
type_: 0,
type_: ValueType::Null as u8,
junk1: 0,
junk2: 0,
junk3: 0,
data: byondapi_sys::ByondValueData { ref_: 0 },
})
}

pub fn new_ref(typ: ByondValueType, ptr: u4c) -> Self {
pub fn new_ref(typ: ValueType, ptr: u4c) -> Self {
Self(CByondValue {
type_: typ,
type_: typ as u8,
junk1: 0,
junk2: 0,
junk3: 0,
Expand All @@ -39,7 +39,7 @@ impl ByondValue {

pub fn new_num(f: f32) -> Self {
Self(CByondValue {
type_: 0x2A,
type_: ValueType::Number as u8,
junk1: 0,
junk2: 0,
junk3: 0,
Expand All @@ -49,7 +49,7 @@ impl ByondValue {

pub fn new_global_ref() -> Self {
Self(CByondValue {
type_: 0x0E,
type_: ValueType::World as u8,
junk1: 0,
junk2: 0,
junk3: 0,
Expand All @@ -64,7 +64,7 @@ impl ByondValue {
return Err(Error::UnableToCreateString);
}
Ok(Self(CByondValue {
type_: 0x06,
type_: ValueType::String as u8,
junk1: 0,
junk2: 0,
junk3: 0,
Expand All @@ -80,11 +80,3 @@ impl ByondValue {
Ok(new_self)
}
}

impl<'a> ByondValue {
/// # Safety
/// The [`CByondValue`] must be initialized.
pub unsafe fn from_ref(s: &'a CByondValue) -> &'a Self {
unsafe { std::mem::transmute(s) }
}
}
2 changes: 1 addition & 1 deletion crates/byondapi-rs/src/value/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ffi::CString;
use byondapi_sys::{u4c, ByondValueType, CByondValue};

use super::ByondValue;
use crate::{map::byond_length, static_global::byond, typecheck_trait::ByondTypeCheck, Error};
use crate::{map::byond_length, static_global::byond, Error};

/// # Compatibility with the C++ API
impl ByondValue {
Expand Down
5 changes: 1 addition & 4 deletions crates/byondapi-rs/src/value/list.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
byond_string_internal, static_global::byond, typecheck_trait::ByondTypeCheck,
value::ByondValue, Error,
};
use crate::{byond_string_internal, static_global::byond, value::ByondValue, Error};
/// List stuff goes here, Keep in mind that all indexing method starts at zero instead of one like byondland
impl ByondValue {
/// Gets an array of all the list elements, this means keys for assoc lists and values for regular lists
Expand Down
Loading

0 comments on commit aa8b2e2

Please sign in to comment.