hex_patch/app/plugins/
plugin_instant.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use std::time::Instant;

use mlua::UserData;

#[derive(Clone, Copy, Debug)]
pub struct PluginInstant {
    pub inner: Instant,
}

impl PluginInstant {
    pub fn now() -> Self {
        Self {
            inner: Instant::now(),
        }
    }
}

impl UserData for PluginInstant {
    fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
        methods.add_method("elapsed", |_, this, ()| {
            Ok(this.inner.elapsed().as_secs_f64())
        });
    }
}