hex_patch/app/plugins/plugin_instant.rs
1use std::time::Instant;
2
3use mlua::UserData;
4
5#[derive(Clone, Copy, Debug)]
6pub struct PluginInstant {
7 pub inner: Instant,
8}
9
10impl PluginInstant {
11 pub fn now() -> Self {
12 Self {
13 inner: Instant::now(),
14 }
15 }
16}
17
18impl UserData for PluginInstant {
19 fn add_methods<'lua, M: mlua::UserDataMethods<Self>>(methods: &mut M) {
20 methods.add_method("elapsed", |_, this, ()| {
21 Ok(this.inner.elapsed().as_secs_f64())
22 });
23 }
24}