From 71513be332067a5a5c3aca9486dc77250be3260e Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Tue, 28 Feb 2023 17:51:54 +0800 Subject: [PATCH] feat: export basic ranges --- src/cli/Cargo.lock | 1 + src/cli/src/main.rs | 7 +++-- src/rust_ffi/Cargo.lock | 1 + src/rust_ffi/Cargo.toml | 1 + src/rust_ffi/src/all_cases.rs | 52 +++++++++++++++++++++++++++++++++++ src/rust_ffi/src/lib.rs | 6 ++++ 6 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 src/rust_ffi/src/all_cases.rs diff --git a/src/cli/Cargo.lock b/src/cli/Cargo.lock index 2c6568e..6a38f39 100644 --- a/src/cli/Cargo.lock +++ b/src/cli/Cargo.lock @@ -80,6 +80,7 @@ name = "klotski_ffi" version = "0.1.0" dependencies = [ "bindgen", + "lazy_static", ] [[package]] diff --git a/src/cli/src/main.rs b/src/cli/src/main.rs index 27a3b67..e8c27ac 100644 --- a/src/cli/src/main.rs +++ b/src/cli/src/main.rs @@ -36,7 +36,10 @@ fn main() { // let r = klotski_ffi::RawCode::from(0x0_E58_FC8_5FF_EBC_4DB).unwrap(); // 4FEA13400 // let r = klotski_ffi::RawCode::from(0x0_EDB_5FF_EBC_5C8_E58).unwrap(); // 8346AFC00 // let r = klotski_ffi::RawCode::from(0x0_0F9_1CF_FFA_F17_6DA).unwrap(); // 6BFA47000 - let r = klotski_ffi::RawCode::from(0x0_603_EDF_5CA_FFF_5E2).unwrap(); // 1A9BF0C00 + // let r = klotski_ffi::RawCode::from(0x0_603_EDF_5CA_FFF_5E2).unwrap(); // 1A9BF0C00 + + // println!("{} => {}", r, r.to_common_code()); + + klotski_ffi::demo(); - println!("{} => {}", r, r.to_common_code()); } diff --git a/src/rust_ffi/Cargo.lock b/src/rust_ffi/Cargo.lock index 2c36b2c..7552030 100644 --- a/src/rust_ffi/Cargo.lock +++ b/src/rust_ffi/Cargo.lock @@ -73,6 +73,7 @@ name = "klotski_ffi" version = "0.1.0" dependencies = [ "bindgen", + "lazy_static", ] [[package]] diff --git a/src/rust_ffi/Cargo.toml b/src/rust_ffi/Cargo.toml index c9d32c4..e069ea3 100644 --- a/src/rust_ffi/Cargo.toml +++ b/src/rust_ffi/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +lazy_static = "1.4.0" [build-dependencies] bindgen = "0.63.0" diff --git a/src/rust_ffi/src/all_cases.rs b/src/rust_ffi/src/all_cases.rs new file mode 100644 index 0000000..3284961 --- /dev/null +++ b/src/rust_ffi/src/all_cases.rs @@ -0,0 +1,52 @@ +use crate::core::Core; + +lazy_static! { + static ref BASIC_RANGES: Vec = { + unsafe { + Core::basic_ranges_build(); + let mut buffer: Vec = vec![0; Core::BASIC_RANGES_SIZE as usize]; + Core::export_basic_ranges(&mut buffer[0]); + buffer + } + }; +} + +// struct BasicRange { +// data: Option> +// } +// +// static mut BASIC_RANGE: BasicRange = BasicRange { +// data: None +// }; + +// impl BasicRange { + // fn fetch(&mut self) -> &Vec { + // match &self.data { + // Some(data) => { + // return data; + // }, + // None => (), + // }; + + // &self.data.unwrap() + // } + + // fn build(&mut self) { + // unsafe { + // Core::basic_ranges_build(); + // let mut buffer: Vec = vec![0; Core::BASIC_RANGES_SIZE as usize]; + // Core::export_basic_ranges(&mut buffer[0]); + // self.data = Some(buffer); + // } + // } +// } + +pub fn demo() { + + println!("demo start"); + + println!("{:?}", (*BASIC_RANGES).len()); + + println!("demo complete"); + +} diff --git a/src/rust_ffi/src/lib.rs b/src/rust_ffi/src/lib.rs index 2045f9b..c09e78a 100644 --- a/src/rust_ffi/src/lib.rs +++ b/src/rust_ffi/src/lib.rs @@ -1,9 +1,15 @@ +#[macro_use] +extern crate lazy_static; + mod core; mod codec; mod metadata; +mod all_cases; pub use codec::RawCode; pub use codec::ShortCode; pub use codec::CommonCode; pub use metadata::load_metadata as metadata; + +pub use all_cases::demo;