Skip to content
2 changes: 2 additions & 0 deletions src/BizHawk.Client.Common/Api/Classes/SaveStateApi.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using System.IO;

namespace BizHawk.Client.Common
Expand Down
18 changes: 10 additions & 8 deletions src/BizHawk.Client.Common/lua/CommonLibs/ClientLuaLibrary.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
Expand All @@ -17,14 +19,14 @@ namespace BizHawk.Client.Common
[Description("A library for manipulating the EmuHawk client UI")]
public sealed class ClientLuaLibrary : LuaLibraryBase, IRegisterFunctions
{
public Lazy<string> AllAPINames { get; set; }
public required Lazy<string> AllAPINames { get; set; }

public NLFAddCallback CreateAndRegisterNamedFunction { get; set; }
public required NLFAddCallback CreateAndRegisterNamedFunction { get; set; }

[OptionalService]
private IVideoProvider VideoProvider { get; set; }
private IVideoProvider? VideoProvider { get; set; }

public IMainFormForApi MainForm { get; set; }
public required IMainFormForApi MainForm { get; set; }

public ClientLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
Expand Down Expand Up @@ -247,7 +249,7 @@ public int ScreenHeight()

[LuaMethodExample("client.screenshot( \"C:\\\" );")]
[LuaMethod("screenshot", "if a parameter is passed it will function as the Screenshot As menu item of EmuHawk, else it will function as the Screenshot menu item")]
public void Screenshot(string path = null)
public void Screenshot(string? path = null)
=> APIs.EmuClient.Screenshot(path);

[LuaMethodExample("client.screenshottoclipboard( );")]
Expand Down Expand Up @@ -287,7 +289,7 @@ public void SetWindowSize(int size)
"No more than `maxFrames` future frames will be emulated. Useful to avoid freezing " +
"the client UI in case of accidentally never returning true from the callback. " +
"Your timeout can be as low as 1 frame or as high as 32767 frames.")]
public string ShowFuture(LuaFunction luaf, long maxFrames, string name = null)
public string ShowFuture(LuaFunction luaf, long maxFrames, string? name = null)
{
if (maxFrames is < 1 or > EmuClientApi.SHOW_FUTURE_MAX_USER_TIMEOUT)
{
Expand Down Expand Up @@ -367,15 +369,15 @@ public LuaTable GetAvailableTools()

[LuaMethodExample("local nlcliget = client.gettool( \"Tool name\" );")]
[LuaMethod("gettool", "Returns an object that represents a tool of the given name (not case sensitive). If the tool is not open, it will be loaded if available. Use getavailabletools to get a list of names")]
public LuaTable GetTool(string name)
public LuaTable? GetTool(string name)
{
var selectedTool = APIs.Tool.GetTool(name);
return selectedTool == null ? null : _th.ObjectToTable(selectedTool);
}

[LuaMethodExample("local nlclicre = client.createinstance( \"objectname\" );")]
[LuaMethod("createinstance", "returns a default instance of the given type of object if it exists (not case sensitive). Note: This will only work on objects which have a parameterless constructor. If no suitable type is found, or the type does not have a parameterless constructor, then nil is returned")]
public LuaTable CreateInstance(string name)
public LuaTable? CreateInstance(string name)
{
var instance = APIs.Tool.CreateInstance(name);
return instance == null ? null : _th.ObjectToTable(instance);
Expand Down
50 changes: 26 additions & 24 deletions src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand Down Expand Up @@ -31,17 +33,17 @@ public static string GetLuaFunctionsList()

[LuaMethod("socketServerIsConnected", "socketServerIsConnected")]
public bool SocketServerIsConnected()
=> APIs.Comm.Sockets.Connected;
=> APIs.Comm.Sockets!.Connected;

[LuaMethod("socketServerScreenShot", "sends a screenshot to the Socket server")]
public string SocketServerScreenShot()
public string? SocketServerScreenShot()
{
CheckSocketServer();
return APIs.Comm.Sockets?.SendScreenshot();
}

[LuaMethod("socketServerScreenShotResponse", "sends a screenshot to the Socket server and retrieves the response")]
public string SocketServerScreenShotResponse()
public string? SocketServerScreenShotResponse()
{
CheckSocketServer();
return APIs.Comm.Sockets?.SendScreenshot(1000);
Expand All @@ -54,18 +56,18 @@ public int SocketServerSend(string SendString)
{
return -1;
}
return APIs.Comm.Sockets.SendString(SendString);
return APIs.Comm.Sockets!.SendString(SendString);
}

[LuaMethod("socketServerSendBytes", "sends bytes to the Socket server")]
public int SocketServerSendBytes(LuaTable byteArray)
{
if (!CheckSocketServer()) return -1;
return APIs.Comm.Sockets.SendBytes(_th.EnumerateValues<long>(byteArray).Select(l => (byte) l).ToArray());
return APIs.Comm.Sockets!.SendBytes(_th.EnumerateValues<long>(byteArray).Select(l => (byte) l).ToArray());
}

[LuaMethod("socketServerResponse", "Receives a message from the Socket server. Since BizHawk 2.6.2, all responses must be of the form $\"{msg.Length:D} {msg}\" i.e. prefixed with the length in base-10 and a space.")]
public string SocketServerResponse()
public string? SocketServerResponse()
{
CheckSocketServer();
return APIs.Comm.Sockets?.ReceiveString();
Expand All @@ -74,7 +76,7 @@ public string SocketServerResponse()
[LuaMethod("socketServerSuccessful", "returns the status of the last Socket server action")]
public bool SocketServerSuccessful()
{
return CheckSocketServer() && APIs.Comm.Sockets.Successful;
return CheckSocketServer() && APIs.Comm.Sockets!.Successful;
}

[LuaMethod("socketServerSetTimeout", "sets the timeout in milliseconds for receiving messages")]
Expand All @@ -88,18 +90,18 @@ public void SocketServerSetTimeout(int timeout)
public void SocketServerSetIp(string ip)
{
CheckSocketServer();
APIs.Comm.Sockets.IP = ip;
APIs.Comm.Sockets!.IP = ip;
}

[LuaMethod("socketServerSetPort", "sets the port of the Lua socket server")]
public void SocketServerSetPort(ushort port)
{
CheckSocketServer();
APIs.Comm.Sockets.Port = port;
APIs.Comm.Sockets!.Port = port;
}

[LuaMethod("socketServerGetIp", "returns the IP address of the Lua socket server")]
public string SocketServerGetIp()
public string? SocketServerGetIp()
{
return APIs.Comm.Sockets?.IP;
}
Expand All @@ -114,7 +116,7 @@ public string SocketServerGetIp()
public string SocketServerGetInfo()
{
return CheckSocketServer()
? APIs.Comm.Sockets.GetInfo()
? APIs.Comm.Sockets!.GetInfo()
: "";
}

Expand Down Expand Up @@ -155,15 +157,15 @@ public int MmfCopyFromMemory(
string mmf_filename,
long addr,
int length,
string domain)
string? domain = null)
=> APIs.Comm.MMF.WriteToFile(mmf_filename, APIs.Memory.ReadByteRange(addr, length, domain).ToArray());

[LuaMethod("mmfCopyToMemory", "Copy a memory mapped file to a section of the memory")]
public void MmfCopyToMemory(
string mmf_filename,
long addr,
int length,
string domain)
string? domain = null)
=> APIs.Memory.WriteByteRange(addr, APIs.Comm.MMF.ReadBytesFromFile(mmf_filename, length), domain);

[LuaMethod("mmfRead", "Reads a string from a memory mapped file")]
Expand All @@ -177,35 +179,35 @@ public LuaTable MmfReadBytes(string mmf_filename, int expectedSize)

// All HTTP related methods
[LuaMethod("httpTest", "tests HTTP connections")]
public string HttpTest()
public string? HttpTest()
{
_ = APIs.Comm.HTTP!; // to match previous behaviour
return APIs.Comm.HttpTest();
}

[LuaMethod("httpTestGet", "tests the HTTP GET connection")]
public string HttpTestGet()
public string? HttpTestGet()
{
CheckHttp();
return APIs.Comm.HttpTestGet();
}

[LuaMethod("httpGet", "makes a HTTP GET request")]
public string HttpGet(string url)
public string? HttpGet(string url)
{
CheckHttp();
return APIs.Comm.HTTP?.ExecGet(url);
}

[LuaMethod("httpPost", "makes a HTTP POST request")]
public string HttpPost(string url, string payload)
public string? HttpPost(string url, string payload)
{
CheckHttp();
return APIs.Comm.HTTP?.ExecPostAsForm(url: url, payload: payload);
}

[LuaMethod("httpPostScreenshot", "HTTP POST screenshot")]
public string HttpPostScreenshot()
public string? HttpPostScreenshot()
{
CheckHttp();
return APIs.Comm.HTTP?.SendScreenshot();
Expand All @@ -222,25 +224,25 @@ public void HttpSetTimeout(int timeout)
public void HttpSetPostUrl(string url)
{
CheckHttp();
APIs.Comm.HTTP.PostUrl = url;
if (APIs.Comm.HTTP is not null) APIs.Comm.HTTP.PostUrl = url;
}

[LuaMethod("httpSetGetUrl", "Sets HTTP GET URL")]
public void HttpSetGetUrl(string url)
{
CheckHttp();
APIs.Comm.HTTP.GetUrl = url;
if (APIs.Comm.HTTP is not null) APIs.Comm.HTTP.GetUrl = url;
}

[LuaMethod("httpGetPostUrl", "Gets HTTP POST URL")]
public string HttpGetPostUrl()
public string? HttpGetPostUrl()
{
CheckHttp();
return APIs.Comm.HTTP?.PostUrl;
}

[LuaMethod("httpGetGetUrl", "Gets HTTP GET URL")]
public string HttpGetGetUrl()
public string? HttpGetGetUrl()
{
CheckHttp();
return APIs.Comm.HTTP?.GetUrl;
Expand All @@ -257,7 +259,7 @@ private void CheckHttp()
#if ENABLE_WEBSOCKETS
[LuaMethod("ws_open", "Opens a websocket and returns the id so that it can be retrieved later.")]
[LuaMethodExample("local ws_id = comm.ws_open(\"wss://echo.websocket.org\");")]
public string WebSocketOpen(string uri)
public string? WebSocketOpen(string uri)
{
var wsServer = APIs.Comm.WebSockets;
if (wsServer == null)
Expand All @@ -282,7 +284,7 @@ public void WebSocketSend(

[LuaMethod("ws_receive", "Receive a message from a certain websocket id and a maximum number of bytes to read")]
[LuaMethodExample("local ws = comm.ws_receive(ws_id, str_len);")]
public string WebSocketReceive(string guid, int bufferCap)
public string? WebSocketReceive(string guid, int bufferCap)
=> _websockets.TryGetValue(Guid.Parse(guid), out var wrapper)
? wrapper.Receive(bufferCap)
: null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using System.ComponentModel;

using NLua;
Expand All @@ -9,8 +11,8 @@ namespace BizHawk.Client.Common
[Description("A library for interacting with the currently loaded emulator core")]
public sealed class EmulationLuaLibrary : LuaLibraryBase
{
public Action FrameAdvanceCallback { get; set; }
public Action YieldCallback { get; set; }
public required Action FrameAdvanceCallback { get; set; }
public required Action YieldCallback { get; set; }

public EmulationLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
Expand All @@ -36,7 +38,7 @@ public int FrameCount()

[LuaMethodExample("local obemudis = emu.disassemble( 0x8000 );")]
[LuaMethod("disassemble", "Returns the disassembly object (disasm string and length int) for the given PC address. Uses System Bus domain if no domain name provided")]
public LuaTable Disassemble(uint pc, string name = "")
public LuaTable? Disassemble(uint pc, string name = "")
{
var (disasm, length) = APIs.Emulation.Disassemble(pc, name);
if (length is 0) return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using BizHawk.Emulation.Common;

using NLua;
Expand Down Expand Up @@ -30,7 +32,7 @@ public bool InDatabase()

[LuaMethodExample("local stgamget = gameinfo.getstatus( );")]
[LuaMethod("getstatus", "returns the game database status of the currently loaded rom. Statuses are for example: GoodDump, BadDump, Hack, Unknown, NotInDatabase")]
public string GetStatus()
public string? GetStatus()
=> (APIs.Emulation.GetGameInfo()?.Status)?.ToString();

[LuaMethodExample("if ( gameinfo.isstatusbad( ) ) then\r\n\tconsole.log( \"returns the currently loaded rom's game database status is considered 'bad'\" );\r\nend;")]
Expand Down
2 changes: 2 additions & 0 deletions src/BizHawk.Client.Common/lua/CommonLibs/InputLuaLibrary.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using NLua;

namespace BizHawk.Client.Common
Expand Down
2 changes: 2 additions & 0 deletions src/BizHawk.Client.Common/lua/CommonLibs/JoypadLuaLibrary.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using System.Collections.Generic;

using NLua;
Expand Down
Loading
Loading