PkmnLib_rs/src/ffi/static_data/learnable_moves.rs

26 lines
853 B
Rust
Raw Normal View History

2022-09-18 16:02:13 +00:00
use crate::defines::LevelInt;
use crate::ffi::ffi_handle::{FFIHandle, FromFFIHandle};
use crate::ffi::{FFIResult, NonOwnedPtrString};
2022-11-28 19:20:46 +00:00
use crate::static_data::{LearnableMoves, LearnableMovesImpl};
use std::ffi::CStr;
use std::sync::Arc;
2022-09-18 16:02:13 +00:00
2022-10-14 14:53:30 +00:00
/// Instantiates a new Learnable Moves.
2022-09-18 16:02:13 +00:00
#[no_mangle]
extern "C" fn learnable_moves_new(max_level: LevelInt) -> FFIHandle<Arc<dyn LearnableMoves>> {
let p: Arc<dyn LearnableMoves> = Arc::new(LearnableMovesImpl::new(max_level));
FFIHandle::get_handle(p.into())
2022-09-18 16:02:13 +00:00
}
2022-10-14 14:53:30 +00:00
/// Adds a new level move the Pokemon can learn.
2022-09-18 16:02:13 +00:00
#[no_mangle]
unsafe extern "C" fn learnable_moves_add_level_move(
ptr: FFIHandle<Arc<dyn LearnableMoves>>,
2022-09-18 16:02:13 +00:00
level: LevelInt,
move_name: NonOwnedPtrString,
) -> FFIResult<()> {
ptr.from_ffi_handle()
.add_level_move(level, &CStr::from_ptr(move_name).into())
.into()
2022-09-18 16:02:13 +00:00
}