Lua增加更多函数

This commit is contained in:
2026-02-04 01:21:30 +08:00
parent 4841d1b735
commit 79853052ae

View File

@@ -2,8 +2,10 @@
namespace UniLua namespace UniLua
{ {
using System.Diagnostics; using System.Diagnostics;
using System;
using CMLeonOS; using CMLeonOS;
using Sys = Cosmos.System; using Sys = Cosmos.System;
using System.Threading;
internal class LuaOSLib internal class LuaOSLib
{ {
@@ -24,6 +26,9 @@ namespace UniLua
new NameFuncPair("executefile", OS_Executefile), new NameFuncPair("executefile", OS_Executefile),
new NameFuncPair("reboot", OS_Reboot), new NameFuncPair("reboot", OS_Reboot),
new NameFuncPair("shutdown", OS_Shutdown), new NameFuncPair("shutdown", OS_Shutdown),
new NameFuncPair("sleep", OS_Sleep),
new NameFuncPair("beep", OS_Beep),
new NameFuncPair("clear", OS_Clear),
#endif #endif
}; };
@@ -127,6 +132,35 @@ namespace UniLua
lua.PushBoolean(true); lua.PushBoolean(true);
return 1; return 1;
} }
private static int OS_Sleep( ILuaState lua )
{
double seconds = lua.L_CheckNumber(1);
if (seconds < 0)
{
lua.PushNil();
return 1;
}
int milliseconds = (int)(seconds * 1000);
Thread.Sleep(milliseconds);
lua.PushBoolean(true);
return 1;
}
private static int OS_Beep( ILuaState lua )
{
Console.Beep();
lua.PushBoolean(true);
return 1;
}
private static int OS_Clear( ILuaState lua )
{
Console.Clear();
lua.PushBoolean(true);
return 1;
}
#endif #endif
} }
} }