-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlib.rs
More file actions
73 lines (59 loc) · 1.66 KB
/
lib.rs
File metadata and controls
73 lines (59 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use crate::dat::lithtech_dat::LithtechDat;
use crate::dtx::lithtech_dtx::LithtechDtx;
use crate::ltb::lithtech_ltb::LithtechLtb;
use binrw::io::Cursor;
use binrw::BinRead;
use napi_derive::napi;
use napi_shadow::{NapiShadow, NapiShadowRoot};
use std::rc::Rc;
pub mod common;
pub mod dat;
pub mod dtx;
pub mod ltb;
mod util;
#[napi]
pub fn parse_dat(buf: &[u8]) -> <LithtechDat as NapiShadow>::ShadowStruct {
let mut data = Cursor::new(buf);
let dat = LithtechDat::read(&mut data).unwrap();
let root_rc = Rc::new(dat);
<LithtechDat as NapiShadow>::napi_shadow(
root_rc.clone().as_ref(),
root_rc as Rc<dyn NapiShadowRoot>,
)
}
#[napi]
pub fn parse_ltb(buf: &[u8]) -> <LithtechLtb as NapiShadow>::ShadowStruct {
let mut data = Cursor::new(buf);
let ltb = LithtechLtb::read(&mut data).unwrap();
let root_rc = Rc::new(ltb);
<LithtechLtb as NapiShadow>::napi_shadow(
root_rc.clone().as_ref(),
root_rc as Rc<dyn NapiShadowRoot>,
)
}
#[napi]
pub fn parse_dtx(buf: &[u8]) -> <LithtechDtx as NapiShadow>::ShadowStruct {
let mut data = Cursor::new(buf);
let dtx = LithtechDtx::read(&mut data).unwrap();
let root_rc = Rc::new(dtx);
<LithtechDtx as NapiShadow>::napi_shadow(
root_rc.clone().as_ref(),
root_rc as Rc<dyn NapiShadowRoot>,
)
}
#[link(name = "zig-dxt")] // 对应 zig-dxt.a
extern "C" {
fn add(a: i32, b: i32) -> i32;
}
/// 提供一个 Rust 包装函数
pub fn plus_from_zig(a: i32, b: i32) -> i32 {
unsafe { add(a, b) }
}
#[napi]
pub fn plus_100_from_zig(input: i32) -> i32 {
plus_from_zig(input, 100)
}
#[napi]
pub fn plus_100(input: i32) -> i32 {
input + 100
}