Browse Source

feat: export basic ranges

legacy
Dnomd343 2 years ago
parent
commit
71513be332
  1. 1
      src/cli/Cargo.lock
  2. 7
      src/cli/src/main.rs
  3. 1
      src/rust_ffi/Cargo.lock
  4. 1
      src/rust_ffi/Cargo.toml
  5. 52
      src/rust_ffi/src/all_cases.rs
  6. 6
      src/rust_ffi/src/lib.rs

1
src/cli/Cargo.lock

@ -80,6 +80,7 @@ name = "klotski_ffi"
version = "0.1.0"
dependencies = [
"bindgen",
"lazy_static",
]
[[package]]

7
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());
}

1
src/rust_ffi/Cargo.lock

@ -73,6 +73,7 @@ name = "klotski_ffi"
version = "0.1.0"
dependencies = [
"bindgen",
"lazy_static",
]
[[package]]

1
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"

52
src/rust_ffi/src/all_cases.rs

@ -0,0 +1,52 @@
use crate::core::Core;
lazy_static! {
static ref BASIC_RANGES: Vec<u32> = {
unsafe {
Core::basic_ranges_build();
let mut buffer: Vec<u32> = vec![0; Core::BASIC_RANGES_SIZE as usize];
Core::export_basic_ranges(&mut buffer[0]);
buffer
}
};
}
// struct BasicRange {
// data: Option<Vec<u32>>
// }
//
// static mut BASIC_RANGE: BasicRange = BasicRange {
// data: None
// };
// impl BasicRange {
// fn fetch(&mut self) -> &Vec<u32> {
// match &self.data {
// Some(data) => {
// return data;
// },
// None => (),
// };
// &self.data.unwrap()
// }
// fn build(&mut self) {
// unsafe {
// Core::basic_ranges_build();
// let mut buffer: Vec<u32> = 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");
}

6
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;

Loading…
Cancel
Save