This commit is contained in:
Lucas Schwiderski 2023-05-26 22:03:12 +02:00
parent 2da2056cac
commit d1d9042807
Signed by: lucas
GPG key ID: AA12679AAA6DF4D8
4 changed files with 21 additions and 13 deletions

View file

@ -1,2 +0,0 @@
/target
/Cargo.lock

View file

@ -1,16 +1,26 @@
use std::{
ffi::{c_char, CString},
sync::RwLock,
};
mod stingray_sdk; mod stingray_sdk;
use std::ffi::c_char; use crate::stingray_sdk::{GetApiFunction, LoggingApi, PluginApi, PluginApiID};
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"; const PLUGIN_NAME: &str = "dt_p2p";
struct Plugin {
log: Option<LoggingApi>,
}
impl Plugin {
pub const fn new() -> Self {
Self { log: None }
}
}
static PLUGIN: RwLock<Plugin> = RwLock::new(Plugin::new());
#[no_mangle] #[no_mangle]
pub extern "C" fn get_name() -> *const c_char { pub extern "C" fn get_name() -> *const c_char {
let s = CString::new(PLUGIN_NAME).expect("Failed to create CString from plugin name"); let s = CString::new(PLUGIN_NAME).expect("Failed to create CString from plugin name");
@ -21,7 +31,8 @@ pub extern "C" fn get_name() -> *const c_char {
pub extern "C" fn setup_game(get_engine_api: GetApiFunction) { pub extern "C" fn setup_game(get_engine_api: GetApiFunction) {
println!("setup_game"); println!("setup_game");
let log = LoggingApi::get(get_engine_api); PLUGIN.log = Some(LoggingApi::get(get_engine_api));
let log = PLUGIN.log.as_ref().unwrap();
log.info( log.info(
PLUGIN_NAME, PLUGIN_NAME,

View file

@ -1,2 +0,0 @@
/target
/Cargo.lock

View file

@ -0,0 +1 @@