30 lines
954 B
Rust
30 lines
954 B
Rust
use crate::defines::LevelInt;
|
|
use crate::ffi::{BorrowedPtr, ExternPointer, NativeResult, OwnedPtr};
|
|
use crate::static_data::{LearnableMoves, LearnableMovesImpl};
|
|
use std::ffi::{c_char, CStr};
|
|
use std::ptr::drop_in_place;
|
|
|
|
/// Instantiates a new Learnable Moves.
|
|
#[no_mangle]
|
|
extern "C" fn learnable_moves_new(max_level: LevelInt) -> OwnedPtr<Box<dyn LearnableMoves>> {
|
|
Box::into_raw(Box::new(Box::new(LearnableMovesImpl::new(max_level))))
|
|
}
|
|
|
|
/// drops a learnablemoves struct.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn learnable_moves_drop(ptr: OwnedPtr<Box<dyn LearnableMoves>>) {
|
|
drop_in_place(ptr)
|
|
}
|
|
|
|
/// Adds a new level move the Pokemon can learn.
|
|
#[no_mangle]
|
|
unsafe extern "C" fn learnable_moves_add_level_move(
|
|
mut ptr: ExternPointer<Box<dyn LearnableMoves>>,
|
|
level: LevelInt,
|
|
move_name: BorrowedPtr<c_char>,
|
|
) -> NativeResult<()> {
|
|
ptr.as_mut()
|
|
.add_level_move(level, &CStr::from_ptr(move_name).into())
|
|
.into()
|
|
}
|