From 392c1b9acac4744b89462a4505f303be23464d9f Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Fri, 10 Feb 2023 20:43:58 +0100 Subject: [PATCH] Add timer.now() to get current time in milliseconds (UTC) --- Capy64/Runtime/Libraries/Timer.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Capy64/Runtime/Libraries/Timer.cs b/Capy64/Runtime/Libraries/Timer.cs index 63f1811..144cbfe 100644 --- a/Capy64/Runtime/Libraries/Timer.cs +++ b/Capy64/Runtime/Libraries/Timer.cs @@ -15,6 +15,11 @@ class Timer : IPlugin name = "start", function = L_StartTimer, }, + new() + { + name = "now", + function = L_Now + }, new(), }; @@ -82,4 +87,14 @@ class Timer : IPlugin L.PushInteger(timerId); return 1; } + + private static int L_Now(IntPtr state) + { + var now = DateTimeOffset.UtcNow; + var L = Lua.FromIntPtr(state); + + L.PushInteger(now.ToUnixTimeMilliseconds()); + + return 1; + } }