From 2544659d0cc28955559097638f3866391b8cf032 Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Thu, 2 Feb 2023 11:18:38 +0100 Subject: [PATCH] Add machine library to hosts Capy64 related functions --- Capy64/Runtime/Libraries/Machine.cs | 83 ++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 6 deletions(-) diff --git a/Capy64/Runtime/Libraries/Machine.cs b/Capy64/Runtime/Libraries/Machine.cs index c68ed4a..6c5f354 100644 --- a/Capy64/Runtime/Libraries/Machine.cs +++ b/Capy64/Runtime/Libraries/Machine.cs @@ -16,14 +16,33 @@ public class Machine : IPlugin _game = game; } - // todo list - // shutdown, reboot - // set, get title - // get proper version function - // set discord rpc - // private static LuaRegister[] MachineLib = new LuaRegister[] { + new() + { + name = "shutdown", + function = L_Shutdown, + }, + new() + { + name = "reboot", + function = L_Reboot, + }, + new() + { + name = "title", + function = L_Title, + }, + new() + { + name = "version", + function = L_Version, + }, + new() + { + name = "setRPC", + function = L_SetRPC, + }, new(), }; @@ -39,5 +58,57 @@ public class Machine : IPlugin return 1; } + private static int L_Shutdown(IntPtr _) + { + RuntimeManager.Shutdown(); + + return 0; + } + + private static int L_Reboot(IntPtr _) + { + RuntimeManager.Reboot(); + + return 0; + } + + private static int L_Title(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var currentTitle = Capy64.Instance.Window.Title; + + if(!L.IsNoneOrNil(1)) + { + var newTitle = L.CheckString(1); + + Capy64.Instance.Window.Title = newTitle; + } + + L.PushString(currentTitle); + + return 1; + } + + private static int L_Version(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + L.PushString("Capy64 " + Capy64.Version); + + return 1; + } + + private static int L_SetRPC(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var details = L.CheckString(1); + var dstate = L.OptString(2, null); + + Capy64.Instance.Discord.SetPresence(details, dstate); + + return 0; + } }