auto load struct
This commit is contained in:
parent
474841212d
commit
321ece84bc
2 changed files with 45 additions and 9 deletions
|
@ -93,13 +93,40 @@ impl Default for Configurable {
|
|||
}
|
||||
}
|
||||
|
||||
/// A fake trait in the sense that these methods are exposed as symbols, not trait methods
|
||||
pub trait Auto {
|
||||
pub struct Auto {
|
||||
library: Arc<Library>,
|
||||
// these aren't actually static, they have the same lifetime as the library xP
|
||||
configs: &'static [Configurable],
|
||||
name: &'static str,
|
||||
}
|
||||
|
||||
impl Auto {
|
||||
pub fn new(path: &str) -> Result<Self> {
|
||||
let lib = unsafe {Library::new(path)?};
|
||||
let lib = Arc::new(lib);
|
||||
|
||||
let configurations: Symbol<&&[Configurable]> = unsafe {lib.get(b"CONFIGS").unwrap()};
|
||||
|
||||
let name: Symbol<&&'static str> = unsafe {lib.get(b"NAME").unwrap()};
|
||||
|
||||
|
||||
Ok(Self {
|
||||
configs: *configurations,
|
||||
name: *name,
|
||||
library: lib,
|
||||
})
|
||||
|
||||
}
|
||||
/// entrypoint
|
||||
async fn run(interface: &AutoInterface);
|
||||
/// register
|
||||
fn default_configs() -> [Configurable];
|
||||
fn name() -> &'static str;
|
||||
async fn run(&self, interface: &AutoInterface) {
|
||||
}
|
||||
|
||||
pub fn configs(&self) -> &'static [Configurable] {
|
||||
self.configs
|
||||
}
|
||||
pub fn name(&self) -> &'static str {
|
||||
self.name
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::{fmt::format, ops::ControlFlow, result, sync::{atomic::Ordering, Arc},
|
|||
|
||||
use anyhow::{Context, Ok, Result};
|
||||
use atomic_float::AtomicF32;
|
||||
use interface::{auto::get_confs, combatlog::{combat_logger, CombatData}, POWER_THRESHOLD};
|
||||
use interface::{auto::{get_confs, Auto}, combatlog::{combat_logger, CombatData}, POWER_THRESHOLD};
|
||||
use common::{ControlPacket, TelemetryPacket};
|
||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||
use egui_toast::{Toast, ToastKind};
|
||||
|
@ -13,8 +13,17 @@ use tokio::{io::{AsyncReadExt, AsyncWriteExt, BufWriter, WriteHalf}, net::{tcp::
|
|||
|
||||
|
||||
fn main() -> Result<()> {
|
||||
get_confs().unwrap();
|
||||
panic!("got too far");
|
||||
let auto = Auto::new("../auto/target/release/libauto.so")?;
|
||||
|
||||
println!("name: {}", auto.name());
|
||||
|
||||
for config in auto.configs().iter() {
|
||||
println!("co {}", config.name);
|
||||
println!("co {:?}", config.description);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
let (logging_sender, combatlog) = mpsc::channel(64);
|
||||
|
||||
|
|
Loading…
Reference in a new issue