Add machine library to hosts Capy64 related functions

This commit is contained in:
Alessandro Proto 2023-02-02 11:18:38 +01:00
parent 1fbcef2146
commit 2544659d0c

View file

@ -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;
}
}