From 7aa170283e2174db3051c1880e30e58ba7a389b4 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 29 Nov 2019 16:35:21 -0600 Subject: [PATCH] cleanup some lua files --- .../lua/EmuLuaLibrary.Bit.cs | 1 + .../lua/EmuLuaLibrary.Emu.cs | 48 +++++-------- .../lua/EmuLuaLibrary.Events.cs | 2 + .../lua/EmuLuaLibrary.GameInfo.cs | 30 ++------- .../lua/EmuLuaLibrary.Genesis.cs | 11 ++- .../lua/EmuLuaLibrary.Joypad.cs | 1 + .../lua/EmuLuaLibrary.MainMemory.cs | 1 + .../lua/EmuLuaLibrary.Memory.cs | 1 + .../lua/EmuLuaLibrary.MemorySavestate.cs | 2 + .../lua/EmuLuaLibrary.Movie.cs | 9 +-- .../lua/EmuLuaLibrary.NES.cs | 6 +- .../lua/EmuLuaLibrary.SNES.cs | 11 ++- .../lua/EmuLuaLibrary.SQL.cs | 62 ++++++++--------- .../lua/EmuLuaLibrary.String.cs | 67 ++++++------------- .../lua/EmuLuaLibrary.UserData.cs | 3 +- BizHawk.Client.Common/lua/LuaAttributes.cs | 1 - BizHawk.Client.Common/lua/LuaDocumentation.cs | 8 +-- BizHawk.Client.Common/lua/LuaSandbox.cs | 5 +- BizHawk.sln.DotSettings | 2 + 19 files changed, 109 insertions(+), 162 deletions(-) diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Bit.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Bit.cs index e5f8a0e37b..6f085fca19 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Bit.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Bit.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using NLua; +// ReSharper disable UnusedMember.Global namespace BizHawk.Client.Common { [Description("A library for performing standard bitwise operations.")] diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs index da767ebb4c..c723353e7e 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs @@ -11,6 +11,8 @@ using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES; using NLua; +// ReSharper disable UnusedMember.Global +// ReSharper disable UnusedAutoPropertyAccessor.Local namespace BizHawk.Client.Common { [Description("A library for interacting with the currently loaded emulator core")] @@ -267,37 +269,34 @@ namespace BizHawk.Client.Common [LuaMethod("setrenderplanes", "Toggles the drawing of sprites and background planes. Set to false or nil to disable a pane, anything else will draw them")] public void SetRenderPlanes(params bool[] luaParam) { - if (Emulator is NES) + if (Emulator is NES nes) { // in the future, we could do something more arbitrary here. // but this isn't any worse than the old system - var nes = Emulator as NES; var s = nes.GetSettings(); s.DispSprites = luaParam[0]; s.DispBackground = luaParam[1]; nes.PutSettings(s); } - else if (Emulator is QuickNES) + else if (Emulator is QuickNES quicknes) { - var quicknes = Emulator as QuickNES; var s = quicknes.GetSettings(); // this core doesn't support disabling BG - bool showsp = GetSetting(0, luaParam); - if (showsp && s.NumSprites == 0) + bool showSp = GetSetting(0, luaParam); + if (showSp && s.NumSprites == 0) { s.NumSprites = 8; } - else if (!showsp && s.NumSprites > 0) + else if (!showSp && s.NumSprites > 0) { s.NumSprites = 0; } quicknes.PutSettings(s); } - else if (Emulator is PCEngine) + else if (Emulator is PCEngine pce) { - var pce = Emulator as PCEngine; var s = pce.GetSettings(); s.ShowOBJ1 = GetSetting(0, luaParam); s.ShowBG1 = GetSetting(1, luaParam); @@ -309,17 +308,15 @@ namespace BizHawk.Client.Common pce.PutSettings(s); } - else if (Emulator is SMS) + else if (Emulator is SMS sms) { - var sms = Emulator as SMS; var s = sms.GetSettings(); s.DispOBJ = GetSetting(0, luaParam); s.DispBG = GetSetting(1, luaParam); sms.PutSettings(s); } - else if (Emulator is WonderSwan) + else if (Emulator is WonderSwan ws) { - var ws = Emulator as WonderSwan; var s = ws.GetSettings(); s.EnableSprites = GetSetting(0, luaParam); s.EnableFG = GetSetting(1, luaParam); @@ -330,12 +327,7 @@ namespace BizHawk.Client.Common private static bool GetSetting(int index, bool[] settings) { - if (index < settings.Length) - { - return settings[index]; - } - - return true; + return index >= settings.Length || settings[index]; } [LuaMethodExample("emu.yield( );")] @@ -349,24 +341,18 @@ namespace BizHawk.Client.Common [LuaMethod("getdisplaytype", "returns the display type (PAL vs NTSC) that the emulator is currently running in")] public string GetDisplayType() { - if (RegionableCore != null) - { - return RegionableCore.Region.ToString(); - } - - return ""; + return RegionableCore != null + ? RegionableCore.Region.ToString() + : ""; } [LuaMethodExample("local stemuget = emu.getboardname();")] [LuaMethod("getboardname", "returns (if available) the board name of the loaded ROM")] public string GetBoardName() { - if (BoardInfo != null) - { - return BoardInfo.BoardName; - } - - return ""; + return BoardInfo != null + ? BoardInfo.BoardName + : ""; } [LuaMethod("getluacore", "returns the name of the Lua core currently in use")] diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs index 527cbbe551..3ef04e8708 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs @@ -6,6 +6,8 @@ using NLua; using BizHawk.Emulation.Common; using BizHawk.Emulation.Common.IEmulatorExtensions; +// ReSharper disable UnusedMember.Global +// ReSharper disable UnusedAutoPropertyAccessor.Local namespace BizHawk.Client.Common { [Description("A library for registering lua functions to emulator events.\n All events support multiple registered methods.\nAll registered event methods can be named and return a Guid when registered")] diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.GameInfo.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.GameInfo.cs index 61d2d4afb0..5c846844ed 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.GameInfo.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.GameInfo.cs @@ -3,6 +3,8 @@ using NLua; using BizHawk.Emulation.Common; +// ReSharper disable UnusedMember.Global +// ReSharper disable UnusedAutoPropertyAccessor.Local namespace BizHawk.Client.Common { public sealed class GameInfoLuaLibrary : LuaLibraryBase @@ -22,24 +24,14 @@ namespace BizHawk.Client.Common [LuaMethod("getromname", "returns the name of the currently loaded rom, if a rom is loaded")] public string GetRomName() { - if (Global.Game != null) - { - return Global.Game.Name ?? ""; - } - - return ""; + return Global.Game?.Name ?? ""; } [LuaMethodExample("local stgamget = gameinfo.getromhash( );")] [LuaMethod("getromhash", "returns the hash of the currently loaded rom, if a rom is loaded")] public string GetRomHash() { - if (Global.Game != null) - { - return Global.Game.Hash ?? ""; - } - - return ""; + return Global.Game?.Hash ?? ""; } [LuaMethodExample("if ( gameinfo.indatabase( ) ) then\r\n\tconsole.log( \"returns whether or not the currently loaded rom is in the game database\" );\r\nend;")] @@ -58,24 +50,14 @@ namespace BizHawk.Client.Common [LuaMethod("getstatus", "returns the game database status of the currently loaded rom. Statuses are for example: GoodDump, BadDump, Hack, Unknown, NotInDatabase")] public string GetStatus() { - if (Global.Game != null) - { - return Global.Game.Status.ToString(); - } - - return ""; + return Global.Game?.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;")] [LuaMethod("isstatusbad", "returns the currently loaded rom's game database status is considered 'bad'")] public bool IsStatusBad() { - if (Global.Game != null) - { - return Global.Game.IsRomStatusBad(); - } - - return true; + return Global.Game?.IsRomStatusBad() ?? true; } [LuaMethodExample("local stgamget = gameinfo.getboardtype( );")] diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Genesis.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Genesis.cs index de469a25d7..5f51bc827b 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Genesis.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Genesis.cs @@ -6,6 +6,8 @@ using NLua; using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Consoles.Sega.gpgx; +// ReSharper disable UnusedMember.Global +// ReSharper disable UnusedAutoPropertyAccessor.Local namespace BizHawk.Client.Common { [Description("Functions specific to GenesisHawk (functions may not run when an Genesis game is not loaded)")] @@ -24,12 +26,9 @@ namespace BizHawk.Client.Common private GPGX.GPGXSettings GetSettings() { - if (Genesis != null) - { - return Genesis.GetSettings(); - } - - return new GPGX.GPGXSettings(); + return Genesis != null + ? Genesis.GetSettings() + : new GPGX.GPGXSettings(); } private void PutSettings(GPGX.GPGXSettings settings) diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Joypad.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Joypad.cs index 6c8ebe32be..3588c8fff8 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Joypad.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Joypad.cs @@ -1,6 +1,7 @@ using System; using NLua; +// ReSharper disable UnusedMember.Global namespace BizHawk.Client.Common { public sealed class JoypadLuaLibrary : LuaLibraryBase diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.MainMemory.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.MainMemory.cs index 1d41611cde..32516ad061 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.MainMemory.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.MainMemory.cs @@ -5,6 +5,7 @@ using NLua; using BizHawk.Emulation.Common; using BizHawk.Emulation.Common.IEmulatorExtensions; +// ReSharper disable UnusedMember.Global namespace BizHawk.Client.Common { [Description("Main memory library reads and writes from the Main memory domain (the default memory domain set by any given core)")] diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Memory.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Memory.cs index 168920035d..2de8448082 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Memory.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Memory.cs @@ -6,6 +6,7 @@ using BizHawk.Emulation.Common; using BizHawk.Emulation.Common.IEmulatorExtensions; using BizHawk.Common.BufferExtensions; +// ReSharper disable UnusedMember.Global namespace BizHawk.Client.Common { [Description("These functions behavior identically to the mainmemory functions but the user can set the memory domain to read and write from. The default domain is main memory. Use getcurrentmemorydomain(), and usememorydomain() to control which domain is used. Each core has its own set of valid memory domains. Use getmemorydomainlist() to get a list of memory domains for the current core loaded.")] diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.MemorySavestate.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.MemorySavestate.cs index 8ebb3f5875..acd08d9a4c 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.MemorySavestate.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.MemorySavestate.cs @@ -6,6 +6,8 @@ using NLua; using BizHawk.Emulation.Common; +// ReSharper disable UnusedMember.Global +// ReSharper disable UnusedAutoPropertyAccessor.Local namespace BizHawk.Client.Common { public sealed class MemorySavestateEmuLuaLibrary : LuaLibraryBase diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs index 74e15136fb..9b0e1b43f5 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs @@ -2,6 +2,7 @@ using System.IO; using NLua; +// ReSharper disable UnusedMember.Global namespace BizHawk.Client.Common { public sealed class MovieLuaLibrary : LuaLibraryBase @@ -176,9 +177,9 @@ namespace BizHawk.Client.Common { // Lua numbers are always double, integer precision holds up // to 53 bits, so throw an error if it's bigger than that. - const double PrecisionLimit = 9007199254740992d; + const double precisionLimit = 9007199254740992d; - if (count > PrecisionLimit) + if (count > precisionLimit) { throw new Exception("Rerecord count exceeds Lua integer precision."); } @@ -208,8 +209,8 @@ namespace BizHawk.Client.Common { var movie = Global.MovieSession.Movie; var system = movie.HeaderEntries[HeaderKeys.PLATFORM]; - var pal = movie.HeaderEntries.ContainsKey(HeaderKeys.PAL) && - movie.HeaderEntries[HeaderKeys.PAL] == "1"; + var pal = movie.HeaderEntries.ContainsKey(HeaderKeys.PAL) + && movie.HeaderEntries[HeaderKeys.PAL] == "1"; return new PlatformFrameRates()[system, pal]; } diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.NES.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.NES.cs index d1e4ea11b1..8cf9c7ad13 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.NES.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.NES.cs @@ -8,6 +8,8 @@ using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Nintendo.NES; using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES; +// ReSharper disable UnusedMember.Global +// ReSharper disable UnusedAutoPropertyAccessor.Local namespace BizHawk.Client.Common { [Description("Functions related specifically to Nes Cores")] @@ -31,7 +33,7 @@ namespace BizHawk.Client.Common private bool NESAvailable => Neshawk != null || Quicknes != null; - private bool HasMemoryDOmains => MemoryDomains != null; + private bool HasMemoryDomains => MemoryDomains != null; public NesLuaLibrary(Lua lua, Action logOutputCallback) : base(lua, logOutputCallback) { } @@ -42,7 +44,7 @@ namespace BizHawk.Client.Common [LuaMethod("addgamegenie", "Adds the specified game genie code. If an NES game is not currently loaded or the code is not a valid game genie code, this will have no effect")] public void AddGameGenie(string code) { - if (NESAvailable && HasMemoryDOmains) + if (NESAvailable && HasMemoryDomains) { var decoder = new NESGameGenieDecoder(code); var watch = Watch.GenerateWatch( diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.SNES.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.SNES.cs index 3a5bbdc617..2d5cdcd6ac 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.SNES.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.SNES.cs @@ -4,6 +4,8 @@ using BizHawk.Emulation.Common; using NLua; using BizHawk.Emulation.Cores.Nintendo.SNES; +// ReSharper disable UnusedMember.Global +// ReSharper disable UnusedAutoPropertyAccessor.Local namespace BizHawk.Client.Common { [Description("Functions specific to SNESHawk (functions may not run when an SNES game is not loaded)")] @@ -22,12 +24,9 @@ namespace BizHawk.Client.Common private LibsnesCore.SnesSettings GetSettings() { - if (Snes != null) - { - return Snes.GetSettings(); - } - - return new LibsnesCore.SnesSettings(); + return Snes != null + ? Snes.GetSettings() + : new LibsnesCore.SnesSettings(); } private void PutSettings(LibsnesCore.SnesSettings settings) diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.SQL.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.SQL.cs index 00bcfb92c1..6afde80435 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.SQL.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.SQL.cs @@ -4,21 +4,21 @@ using System.ComponentModel; using System.Data.SQLite; using NLua; +// ReSharper disable UnusedMember.Global namespace BizHawk.Client.Common { [Description("A library for performing SQLite operations.")] - public sealed class SQLLuaLibrary : LuaLibraryBase + public sealed class SqlLuaLibrary : LuaLibraryBase { - public SQLLuaLibrary(Lua lua) + public SqlLuaLibrary(Lua lua) : base(lua) { } - public SQLLuaLibrary(Lua lua, Action logOutputCallback) + public SqlLuaLibrary(Lua lua, Action logOutputCallback) : base(lua, logOutputCallback) { } public override string Name => "SQL"; - SQLiteConnection m_dbConnection; - string connectionString; + SQLiteConnection _mDBConnection; [LuaMethodExample("local stSQLcre = SQL.createdatabase( \"eg_db\" );")] [LuaMethod("createdatabase", "Creates a SQLite Database. Name should end with .db")] @@ -29,11 +29,10 @@ namespace BizHawk.Client.Common SQLiteConnection.CreateFile(name); return "Database Created Successfully"; } - catch (SQLiteException sqlEX) + catch (SQLiteException sqlEx) { - return sqlEX.Message; + return sqlEx.Message; } - } @@ -43,21 +42,23 @@ namespace BizHawk.Client.Common { try { - SQLiteConnectionStringBuilder connBuilder = new SQLiteConnectionStringBuilder(); - connBuilder.DataSource = name; - connBuilder.Version = 3; //SQLite version - connBuilder.JournalMode = SQLiteJournalModeEnum.Wal; //Allows for reads and writes to happen at the same time - connBuilder.DefaultIsolationLevel = System.Data.IsolationLevel.ReadCommitted; //This only helps make the database lock left. May be pointless now - connBuilder.SyncMode = SynchronizationModes.Off; //This shortens the delay for do synchronous calls. - m_dbConnection = new SQLiteConnection(connBuilder.ToString()); - connectionString = connBuilder.ToString(); - m_dbConnection.Open(); - m_dbConnection.Close(); + var connBuilder = new SQLiteConnectionStringBuilder + { + DataSource = name + , Version = 3 // SQLite version + , JournalMode = SQLiteJournalModeEnum.Wal // Allows for reads and writes to happen at the same time + , DefaultIsolationLevel = System.Data.IsolationLevel.ReadCommitted // This only helps make the database lock left. May be pointless now + , SyncMode = SynchronizationModes.Off // This shortens the delay for do synchronous calls. + }; + + _mDBConnection = new SQLiteConnection(connBuilder.ToString()); + _mDBConnection.Open(); + _mDBConnection.Close(); return "Database Opened Successfully"; } - catch (SQLiteException sqlEX) + catch (SQLiteException sqlEx) { - return sqlEX.Message; + return sqlEx.Message; } } @@ -72,11 +73,11 @@ namespace BizHawk.Client.Common } try { - m_dbConnection.Open(); + _mDBConnection.Open(); string sql = query; - SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection); + SQLiteCommand command = new SQLiteCommand(sql, _mDBConnection); command.ExecuteNonQuery(); - m_dbConnection.Close(); + _mDBConnection.Close(); return "Command ran successfully"; @@ -87,7 +88,7 @@ namespace BizHawk.Client.Common } catch (SQLiteException sqlEx) { - m_dbConnection.Close(); + _mDBConnection.Close(); return sqlEx.Message; } } @@ -104,9 +105,9 @@ namespace BizHawk.Client.Common try { var table = Lua.NewTable(); - m_dbConnection.Open(); + _mDBConnection.Open(); string sql = $"PRAGMA read_uncommitted =1;{query}"; - SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection); + var command = new SQLiteCommand(sql, _mDBConnection); SQLiteDataReader reader = command.ExecuteReader(); bool rows = reader.HasRows; long rowCount = 0; @@ -124,7 +125,7 @@ namespace BizHawk.Client.Common rowCount += 1; } reader.Close(); - m_dbConnection.Close(); + _mDBConnection.Close(); if (rows == false) { return "No rows found"; @@ -137,12 +138,11 @@ namespace BizHawk.Client.Common { return "Database not opened."; } - catch (SQLiteException sqlEX) + catch (SQLiteException sqlEx) { - m_dbConnection.Close(); - return sqlEX.Message; + _mDBConnection.Close(); + return sqlEx.Message; } } - } } diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.String.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.String.cs index ba1afd211e..51ed286115 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.String.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.String.cs @@ -4,6 +4,7 @@ using System.Linq; using NLua; +// ReSharper disable UnusedMember.Global namespace BizHawk.Client.Common { [Description("A library exposing standard .NET string methods")] @@ -68,96 +69,66 @@ namespace BizHawk.Client.Common [LuaMethod("replace", "Returns a string that replaces all occurances of str2 in str1 with the value of replace")] public static string Replace(string str, string str2, string replace) { - if (string.IsNullOrEmpty(str)) - { - return null; - } - - return str.Replace(str2, replace); + return string.IsNullOrEmpty(str) + ? null + : str.Replace(str2, replace); } [LuaMethodExample("local stbiztou = bizstring.toupper( \"Some string\" );")] [LuaMethod("toupper", "Returns an uppercase version of the given string")] public static string ToUpper(string str) { - if (string.IsNullOrEmpty(str)) - { - return null; - } - - return str.ToUpper(); + return string.IsNullOrEmpty(str) + ? null + : str.ToUpper(); } [LuaMethodExample("local stbiztol = bizstring.tolower( \"Some string\" );")] [LuaMethod("tolower", "Returns an lowercase version of the given string")] public static string ToLower(string str) { - if (string.IsNullOrEmpty(str)) - { - return null; - } - - return str.ToLower(); + return string.IsNullOrEmpty(str) + ? null + : str.ToLower(); } [LuaMethodExample("local stbizsub = bizstring.substring( \"Some string\", 6, 3 );")] [LuaMethod("substring", "Returns a string that represents a substring of str starting at position for the specified length")] public static string SubString(string str, int position, int length) { - if (string.IsNullOrEmpty(str)) - { - return null; - } - - return str.Substring(position, length); + return string.IsNullOrEmpty(str) + ? null + : str.Substring(position, length); } [LuaMethodExample("local stbizrem = bizstring.remove( \"Some string\", 4, 5 );")] [LuaMethod("remove", "Returns a string that represents str with the given position and count removed")] public static string Remove(string str, int position, int count) { - if (string.IsNullOrEmpty(str)) - { - return null; - } - - return str.Remove(position, count); + return string.IsNullOrEmpty(str) + ? null + : str.Remove(position, count); } [LuaMethodExample("if ( bizstring.contains( \"Some string\", \"Some\") ) then\r\n\tconsole.log( \"Returns whether or not str contains str2\" );\r\nend;")] [LuaMethod("contains", "Returns whether or not str contains str2")] public static bool Contains(string str, string str2) { - if (string.IsNullOrEmpty(str)) - { - return false; - } - - return str.Contains(str2); + return !string.IsNullOrEmpty(str) && str.Contains(str2); } [LuaMethodExample("if ( bizstring.startswith( \"Some string\", \"Some\") ) then\r\n\tconsole.log( \"Returns whether str starts with str2\" );\r\nend;")] [LuaMethod("startswith", "Returns whether str starts with str2")] public static bool StartsWith(string str, string str2) { - if (string.IsNullOrEmpty(str)) - { - return false; - } - - return str.StartsWith(str2); + return !string.IsNullOrEmpty(str) && str.StartsWith(str2); } [LuaMethodExample("if ( bizstring.endswith( \"Some string\", \"string\") ) then\r\n\tconsole.log( \"Returns whether str ends wth str2\" );\r\nend;")] [LuaMethod("endswith", "Returns whether str ends wth str2")] public static bool EndsWith(string str, string str2) { - if (string.IsNullOrEmpty(str)) - { - return false; - } - - return str.EndsWith(str2); + return !string.IsNullOrEmpty(str) && str.EndsWith(str2); } [LuaMethodExample("local nlbizspl = bizstring.split( \"Some, string\", \", \" );")] diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.UserData.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.UserData.cs index 088a19de8e..14eaf17707 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.UserData.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.UserData.cs @@ -1,10 +1,9 @@ using System; using System.ComponentModel; - using NLua; - using BizHawk.Client.Common; +// ReSharper disable UnusedMember.Global namespace BizHawk.Client.EmuHawk { [Description("A library for setting and retrieving dynamic data that will be saved and loaded with savestates")] diff --git a/BizHawk.Client.Common/lua/LuaAttributes.cs b/BizHawk.Client.Common/lua/LuaAttributes.cs index 398046f01a..5c012988bd 100644 --- a/BizHawk.Client.Common/lua/LuaAttributes.cs +++ b/BizHawk.Client.Common/lua/LuaAttributes.cs @@ -23,7 +23,6 @@ namespace BizHawk.Client.Common Example = example; } - public string Name { get; } public string Example { get; } } diff --git a/BizHawk.Client.Common/lua/LuaDocumentation.cs b/BizHawk.Client.Common/lua/LuaDocumentation.cs index 8b6b40737e..bf29edf54e 100644 --- a/BizHawk.Client.Common/lua/LuaDocumentation.cs +++ b/BizHawk.Client.Common/lua/LuaDocumentation.cs @@ -186,13 +186,13 @@ __Types and notation__ public string Example => _luaExampleAttribute?.Example; - private string _paramterList = null; + private string _parameterList; public string ParameterList { get { - if (_paramterList == null) + if (_parameterList == null) { var parameters = _method.GetParameters(); @@ -218,10 +218,10 @@ __Types and notation__ } list.Append(')'); - _paramterList = list.ToString(); + _parameterList = list.ToString(); } - return _paramterList; + return _parameterList; } } diff --git a/BizHawk.Client.Common/lua/LuaSandbox.cs b/BizHawk.Client.Common/lua/LuaSandbox.cs index 80fa7ec918..9559949d10 100644 --- a/BizHawk.Client.Common/lua/LuaSandbox.cs +++ b/BizHawk.Client.Common/lua/LuaSandbox.cs @@ -30,7 +30,7 @@ namespace BizHawk.Client.Common { string target = $"{_currentDirectory}\\"; - // first we'll bypass it with a general hack: dont do any setting if the value's already there (even at the OS level, setting the directory can be slow) + // first we'll bypass it with a general hack: don't do any setting if the value's already there (even at the OS level, setting the directory can be slow) // yeah I know, not the smoothest move to compare strings here, in case path normalization is happening at some point // but you got any better ideas? if (currDirSpeedHack == null) @@ -117,8 +117,7 @@ namespace BizHawk.Client.Common lock (SandboxForThread) { - LuaSandbox sandbox; - if (SandboxForThread.TryGetValue(thread, out sandbox)) + if (SandboxForThread.TryGetValue(thread, out var sandbox)) { return sandbox; } diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index 5c65fea643..ddd4c5b89d 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -193,6 +193,7 @@ True True True + True True True True @@ -254,6 +255,7 @@ True True True + True True True True