From 4841d1b735e7477ad9aa7f94205d393a01a8af80 Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Wed, 4 Feb 2026 01:08:44 +0800 Subject: [PATCH] =?UTF-8?q?Lua=E5=A2=9E=E5=8A=A0=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E5=91=BD=E4=BB=A4&=E9=87=8D=E5=90=AF=E5=85=B3=E6=9C=BA?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UniLua/LuaOsLib.cs | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/UniLua/LuaOsLib.cs b/UniLua/LuaOsLib.cs index 90e343f..cf60263 100644 --- a/UniLua/LuaOsLib.cs +++ b/UniLua/LuaOsLib.cs @@ -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 } }