From c362952f7cea7317a74ad331a3ce4666c3efecf2 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Sun, 31 Aug 2025 05:36:36 +0200 Subject: [PATCH] Feature: Get current ms since unix epoch in lua --- src/main.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main.rs b/src/main.rs index 6c01929..024e716 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ mod web; use std::net::SocketAddr; use std::path::Path; use std::process; +use std::time::{SystemTime, UNIX_EPOCH}; use anyhow::anyhow; use automation_lib::config::{FulfillmentConfig, MqttConfig}; @@ -110,6 +111,13 @@ async fn app() -> anyhow::Result<()> { .map_err(mlua::ExternalError::into_lua_err) })?; util.set("get_hostname", get_hostname)?; + let get_epoch = lua.create_function(|_lua, ()| { + Ok(SystemTime::now() + .duration_since(UNIX_EPOCH) + .expect("Time is after UNIX EPOCH") + .as_millis()) + })?; + util.set("get_epoch", get_epoch)?; automation.set("util", util)?; lua.globals().set("automation", automation)?;