added sleep functions for Lua to client module

This commit is contained in:
Ashafix 2019-04-12 19:03:14 +02:00
parent b2584145d7
commit 598723266e
1 changed files with 27 additions and 0 deletions

View File

@ -7,6 +7,8 @@ using NLua;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Client.Common;
using System.Threading;
using System.Diagnostics;
// ReSharper disable StringLiteralTypo
// ReSharper disable UnusedMember.Global
@ -472,5 +474,30 @@ namespace BizHawk.Client.EmuHawk
{
GlobalWin.MainForm.FlushSaveRAM();
}
[LuaMethodExample("client.sleep( 50 );")]
[LuaMethod("sleep", "sleeps for n milliseconds")]
public void Sleep(int millis)
{
Thread.Sleep(millis);
}
[LuaMethodExample("client.exactsleep( 50 );")]
[LuaMethod("exactsleep", "sleeps exactly for n milliseconds")]
public void ExactSleep(int millis)
{
Stopwatch stopwatch = Stopwatch.StartNew();
while (millis - stopwatch.ElapsedMilliseconds > 100)
{
Thread.Sleep(50);
}
while (true)
{
if (stopwatch.ElapsedMilliseconds >= millis)
{
break;
}
}
}
}
}