PkmnLib_rs/src/ffi/static_data/learnable_moves.rs

28 lines
895 B
Rust
Raw Normal View History

2022-09-18 16:02:13 +00:00
use crate::defines::LevelInt;
use crate::ffi::{BorrowedPtr, ExternPointer, OwnedPtr};
2022-11-28 19:20:46 +00:00
use crate::static_data::{LearnableMoves, LearnableMovesImpl};
2022-09-18 16:02:13 +00:00
use std::ffi::{c_char, CStr};
use std::ptr::drop_in_place;
2022-10-14 14:53:30 +00:00
/// Instantiates a new Learnable Moves.
2022-09-18 16:02:13 +00:00
#[no_mangle]
2022-12-25 11:55:09 +00:00
extern "C" fn learnable_moves_new(max_level: LevelInt) -> OwnedPtr<Box<dyn LearnableMoves>> {
Box::into_raw(Box::new(Box::new(LearnableMovesImpl::new(max_level))))
2022-09-18 16:02:13 +00:00
}
2022-10-14 14:53:30 +00:00
/// drops a learnablemoves struct.
2022-09-18 16:02:13 +00:00
#[no_mangle]
2022-11-28 19:20:46 +00:00
unsafe extern "C" fn learnable_moves_drop(ptr: OwnedPtr<Box<dyn LearnableMoves>>) {
2022-09-18 16:02:13 +00:00
drop_in_place(ptr)
}
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(
2022-11-28 19:20:46 +00:00
mut ptr: ExternPointer<Box<dyn LearnableMoves>>,
2022-09-18 16:02:13 +00:00
level: LevelInt,
move_name: BorrowedPtr<c_char>,
) {
ptr.as_mut().add_level_move(level, &CStr::from_ptr(move_name).into())
}