mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-03-03 15:30:27 +00:00
Lua增加运行命令&重启关机函数
This commit is contained in:
@@ -3,6 +3,7 @@ namespace UniLua
|
||||
{
|
||||
using System.Diagnostics;
|
||||
using CMLeonOS;
|
||||
using Sys = Cosmos.System;
|
||||
|
||||
internal class LuaOSLib
|
||||
{
|
||||
@@ -19,6 +20,10 @@ namespace UniLua
|
||||
new NameFuncPair("setenv", OS_Setenv),
|
||||
new NameFuncPair("delenv", OS_Delenv),
|
||||
new NameFuncPair("addenv", OS_Addenv),
|
||||
new NameFuncPair("execute", OS_Execute),
|
||||
new NameFuncPair("executefile", OS_Executefile),
|
||||
new NameFuncPair("reboot", OS_Reboot),
|
||||
new NameFuncPair("shutdown", OS_Shutdown),
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -80,6 +85,48 @@ namespace UniLua
|
||||
lua.PushBoolean(true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int OS_Execute( ILuaState lua )
|
||||
{
|
||||
string command = lua.L_CheckString(1);
|
||||
if (string.IsNullOrWhiteSpace(command))
|
||||
{
|
||||
lua.PushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
CMLeonOS.Kernel.shell?.ExecuteCommand(command);
|
||||
lua.PushBoolean(true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int OS_Executefile( ILuaState lua )
|
||||
{
|
||||
string filePath = lua.L_CheckString(1);
|
||||
if (string.IsNullOrWhiteSpace(filePath))
|
||||
{
|
||||
lua.PushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
CMLeonOS.Kernel.shell?.ExecuteCommand($"com {filePath}");
|
||||
lua.PushBoolean(true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int OS_Reboot( ILuaState lua )
|
||||
{
|
||||
Sys.Power.Reboot();
|
||||
lua.PushBoolean(true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int OS_Shutdown( ILuaState lua )
|
||||
{
|
||||
Sys.Power.Shutdown();
|
||||
lua.PushBoolean(true);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user