53 lines
1.2 KiB
Rust
53 lines
1.2 KiB
Rust
mod stingray_sdk;
|
|
|
|
use std::ffi::c_char;
|
|
use std::ffi::CString;
|
|
|
|
use stingray_sdk::GetApiFunction;
|
|
use stingray_sdk::PluginApi;
|
|
use stingray_sdk::PluginApiID;
|
|
|
|
use crate::stingray_sdk::LoggingApi;
|
|
|
|
const PLUGIN_NAME: &str = "dt_p2p";
|
|
|
|
#[no_mangle]
|
|
pub extern "C" fn get_name() -> *const c_char {
|
|
let s = CString::new(PLUGIN_NAME).expect("Failed to create CString from plugin name");
|
|
s.as_ptr()
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub extern "C" fn setup_game(get_engine_api: GetApiFunction) {
|
|
println!("setup_game");
|
|
|
|
let log = LoggingApi::get(get_engine_api);
|
|
|
|
log.info(
|
|
PLUGIN_NAME,
|
|
format!("Hello, world! This is {}!", PLUGIN_NAME),
|
|
);
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub extern "C" fn shutdown_game() {
|
|
println!("shutdown_game");
|
|
|
|
// log.info(PLUGIN_NAME, format!("Goodbye, world!", PLUGIN_NAME));
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub extern "C" fn get_plugin_api(id: PluginApiID) -> *mut PluginApi {
|
|
if id == PluginApiID::PLUGIN_API_ID {
|
|
let api = PluginApi {
|
|
get_name: Some(get_name),
|
|
setup_game: Some(setup_game),
|
|
shutdown_game: Some(shutdown_game),
|
|
..Default::default()
|
|
};
|
|
|
|
Box::into_raw(Box::new(api))
|
|
} else {
|
|
std::ptr::null_mut()
|
|
}
|
|
}
|