GUI测试+Lua增加计时器

This commit is contained in:
2026-02-05 13:15:17 +08:00
parent 66790be755
commit 33012c48e6
15 changed files with 174 additions and 27 deletions

View File

@@ -11,12 +11,14 @@ namespace UniLua
{
public const string LIB_NAME = "os";
private static DateTime? _timerStartTime;
public static int OpenLib( ILuaState lua )
{
NameFuncPair[] define = new NameFuncPair[]
{
#if !UNITY_WEBPLAYER
new NameFuncPair("clock", OS_Clock),
new NameFuncPair("clock", OS_Clock),
new NameFuncPair("gethostname", OS_Gethostname),
new NameFuncPair("getenv", OS_Getenv),
new NameFuncPair("setenv", OS_Setenv),
@@ -34,6 +36,8 @@ namespace UniLua
new NameFuncPair("sha256", OS_Sha256),
new NameFuncPair("base64encrypt", OS_Base64Encrypt),
new NameFuncPair("base64decrypt", OS_Base64Decrypt),
new NameFuncPair("timerstart", OS_TimerStart),
new NameFuncPair("timerstop", OS_TimerStop),
#endif
};
@@ -204,6 +208,29 @@ namespace UniLua
lua.PushString(decoded);
return 1;
}
private static int OS_TimerStart( ILuaState lua )
{
_timerStartTime = DateTime.Now;
lua.PushBoolean(true);
return 1;
}
private static int OS_TimerStop( ILuaState lua )
{
if (!_timerStartTime.HasValue)
{
lua.PushNil();
return 1;
}
TimeSpan elapsed = DateTime.Now - _timerStartTime.Value;
double elapsedSeconds = elapsed.TotalSeconds;
lua.PushNumber(elapsedSeconds);
_timerStartTime = null;
return 1;
}
#endif
}
}