cleanup some lua files
This commit is contained in:
parent
2a12cac9e5
commit
7aa170283e
|
@ -3,6 +3,7 @@ using System.ComponentModel;
|
||||||
|
|
||||||
using NLua;
|
using NLua;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
[Description("A library for performing standard bitwise operations.")]
|
[Description("A library for performing standard bitwise operations.")]
|
||||||
|
|
|
@ -11,6 +11,8 @@ using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES;
|
||||||
|
|
||||||
using NLua;
|
using NLua;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
|
// ReSharper disable UnusedAutoPropertyAccessor.Local
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
[Description("A library for interacting with the currently loaded emulator core")]
|
[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")]
|
[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)
|
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.
|
// in the future, we could do something more arbitrary here.
|
||||||
// but this isn't any worse than the old system
|
// but this isn't any worse than the old system
|
||||||
var nes = Emulator as NES;
|
|
||||||
var s = nes.GetSettings();
|
var s = nes.GetSettings();
|
||||||
s.DispSprites = luaParam[0];
|
s.DispSprites = luaParam[0];
|
||||||
s.DispBackground = luaParam[1];
|
s.DispBackground = luaParam[1];
|
||||||
nes.PutSettings(s);
|
nes.PutSettings(s);
|
||||||
}
|
}
|
||||||
else if (Emulator is QuickNES)
|
else if (Emulator is QuickNES quicknes)
|
||||||
{
|
{
|
||||||
var quicknes = Emulator as QuickNES;
|
|
||||||
var s = quicknes.GetSettings();
|
var s = quicknes.GetSettings();
|
||||||
|
|
||||||
// this core doesn't support disabling BG
|
// this core doesn't support disabling BG
|
||||||
bool showsp = GetSetting(0, luaParam);
|
bool showSp = GetSetting(0, luaParam);
|
||||||
if (showsp && s.NumSprites == 0)
|
if (showSp && s.NumSprites == 0)
|
||||||
{
|
{
|
||||||
s.NumSprites = 8;
|
s.NumSprites = 8;
|
||||||
}
|
}
|
||||||
else if (!showsp && s.NumSprites > 0)
|
else if (!showSp && s.NumSprites > 0)
|
||||||
{
|
{
|
||||||
s.NumSprites = 0;
|
s.NumSprites = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
quicknes.PutSettings(s);
|
quicknes.PutSettings(s);
|
||||||
}
|
}
|
||||||
else if (Emulator is PCEngine)
|
else if (Emulator is PCEngine pce)
|
||||||
{
|
{
|
||||||
var pce = Emulator as PCEngine;
|
|
||||||
var s = pce.GetSettings();
|
var s = pce.GetSettings();
|
||||||
s.ShowOBJ1 = GetSetting(0, luaParam);
|
s.ShowOBJ1 = GetSetting(0, luaParam);
|
||||||
s.ShowBG1 = GetSetting(1, luaParam);
|
s.ShowBG1 = GetSetting(1, luaParam);
|
||||||
|
@ -309,17 +308,15 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
pce.PutSettings(s);
|
pce.PutSettings(s);
|
||||||
}
|
}
|
||||||
else if (Emulator is SMS)
|
else if (Emulator is SMS sms)
|
||||||
{
|
{
|
||||||
var sms = Emulator as SMS;
|
|
||||||
var s = sms.GetSettings();
|
var s = sms.GetSettings();
|
||||||
s.DispOBJ = GetSetting(0, luaParam);
|
s.DispOBJ = GetSetting(0, luaParam);
|
||||||
s.DispBG = GetSetting(1, luaParam);
|
s.DispBG = GetSetting(1, luaParam);
|
||||||
sms.PutSettings(s);
|
sms.PutSettings(s);
|
||||||
}
|
}
|
||||||
else if (Emulator is WonderSwan)
|
else if (Emulator is WonderSwan ws)
|
||||||
{
|
{
|
||||||
var ws = Emulator as WonderSwan;
|
|
||||||
var s = ws.GetSettings();
|
var s = ws.GetSettings();
|
||||||
s.EnableSprites = GetSetting(0, luaParam);
|
s.EnableSprites = GetSetting(0, luaParam);
|
||||||
s.EnableFG = GetSetting(1, luaParam);
|
s.EnableFG = GetSetting(1, luaParam);
|
||||||
|
@ -330,12 +327,7 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
private static bool GetSetting(int index, bool[] settings)
|
private static bool GetSetting(int index, bool[] settings)
|
||||||
{
|
{
|
||||||
if (index < settings.Length)
|
return index >= settings.Length || settings[index];
|
||||||
{
|
|
||||||
return settings[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LuaMethodExample("emu.yield( );")]
|
[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")]
|
[LuaMethod("getdisplaytype", "returns the display type (PAL vs NTSC) that the emulator is currently running in")]
|
||||||
public string GetDisplayType()
|
public string GetDisplayType()
|
||||||
{
|
{
|
||||||
if (RegionableCore != null)
|
return RegionableCore != null
|
||||||
{
|
? RegionableCore.Region.ToString()
|
||||||
return RegionableCore.Region.ToString();
|
: "";
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LuaMethodExample("local stemuget = emu.getboardname();")]
|
[LuaMethodExample("local stemuget = emu.getboardname();")]
|
||||||
[LuaMethod("getboardname", "returns (if available) the board name of the loaded ROM")]
|
[LuaMethod("getboardname", "returns (if available) the board name of the loaded ROM")]
|
||||||
public string GetBoardName()
|
public string GetBoardName()
|
||||||
{
|
{
|
||||||
if (BoardInfo != null)
|
return BoardInfo != null
|
||||||
{
|
? BoardInfo.BoardName
|
||||||
return BoardInfo.BoardName;
|
: "";
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LuaMethod("getluacore", "returns the name of the Lua core currently in use")]
|
[LuaMethod("getluacore", "returns the name of the Lua core currently in use")]
|
||||||
|
|
|
@ -6,6 +6,8 @@ using NLua;
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
using BizHawk.Emulation.Common.IEmulatorExtensions;
|
using BizHawk.Emulation.Common.IEmulatorExtensions;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
|
// ReSharper disable UnusedAutoPropertyAccessor.Local
|
||||||
namespace BizHawk.Client.Common
|
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")]
|
[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")]
|
||||||
|
|
|
@ -3,6 +3,8 @@ using NLua;
|
||||||
|
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
|
// ReSharper disable UnusedAutoPropertyAccessor.Local
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
public sealed class GameInfoLuaLibrary : LuaLibraryBase
|
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")]
|
[LuaMethod("getromname", "returns the name of the currently loaded rom, if a rom is loaded")]
|
||||||
public string GetRomName()
|
public string GetRomName()
|
||||||
{
|
{
|
||||||
if (Global.Game != null)
|
return Global.Game?.Name ?? "";
|
||||||
{
|
|
||||||
return Global.Game.Name ?? "";
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LuaMethodExample("local stgamget = gameinfo.getromhash( );")]
|
[LuaMethodExample("local stgamget = gameinfo.getromhash( );")]
|
||||||
[LuaMethod("getromhash", "returns the hash of the currently loaded rom, if a rom is loaded")]
|
[LuaMethod("getromhash", "returns the hash of the currently loaded rom, if a rom is loaded")]
|
||||||
public string GetRomHash()
|
public string GetRomHash()
|
||||||
{
|
{
|
||||||
if (Global.Game != null)
|
return Global.Game?.Hash ?? "";
|
||||||
{
|
|
||||||
return Global.Game.Hash ?? "";
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LuaMethodExample("if ( gameinfo.indatabase( ) ) then\r\n\tconsole.log( \"returns whether or not the currently loaded rom is in the game database\" );\r\nend;")]
|
[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")]
|
[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()
|
||||||
{
|
{
|
||||||
if (Global.Game != null)
|
return Global.Game?.Status.ToString();
|
||||||
{
|
|
||||||
return Global.Game.Status.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LuaMethodExample("if ( gameinfo.isstatusbad( ) ) then\r\n\tconsole.log( \"returns the currently loaded rom's game database status is considered 'bad'\" );\r\nend;")]
|
[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'")]
|
[LuaMethod("isstatusbad", "returns the currently loaded rom's game database status is considered 'bad'")]
|
||||||
public bool IsStatusBad()
|
public bool IsStatusBad()
|
||||||
{
|
{
|
||||||
if (Global.Game != null)
|
return Global.Game?.IsRomStatusBad() ?? true;
|
||||||
{
|
|
||||||
return Global.Game.IsRomStatusBad();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LuaMethodExample("local stgamget = gameinfo.getboardtype( );")]
|
[LuaMethodExample("local stgamget = gameinfo.getboardtype( );")]
|
||||||
|
|
|
@ -6,6 +6,8 @@ using NLua;
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
using BizHawk.Emulation.Cores.Consoles.Sega.gpgx;
|
using BizHawk.Emulation.Cores.Consoles.Sega.gpgx;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
|
// ReSharper disable UnusedAutoPropertyAccessor.Local
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
[Description("Functions specific to GenesisHawk (functions may not run when an Genesis game is not loaded)")]
|
[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()
|
private GPGX.GPGXSettings GetSettings()
|
||||||
{
|
{
|
||||||
if (Genesis != null)
|
return Genesis != null
|
||||||
{
|
? Genesis.GetSettings()
|
||||||
return Genesis.GetSettings();
|
: new GPGX.GPGXSettings();
|
||||||
}
|
|
||||||
|
|
||||||
return new GPGX.GPGXSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PutSettings(GPGX.GPGXSettings settings)
|
private void PutSettings(GPGX.GPGXSettings settings)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using NLua;
|
using NLua;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
public sealed class JoypadLuaLibrary : LuaLibraryBase
|
public sealed class JoypadLuaLibrary : LuaLibraryBase
|
||||||
|
|
|
@ -5,6 +5,7 @@ using NLua;
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
using BizHawk.Emulation.Common.IEmulatorExtensions;
|
using BizHawk.Emulation.Common.IEmulatorExtensions;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
namespace BizHawk.Client.Common
|
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)")]
|
[Description("Main memory library reads and writes from the Main memory domain (the default memory domain set by any given core)")]
|
||||||
|
|
|
@ -6,6 +6,7 @@ using BizHawk.Emulation.Common;
|
||||||
using BizHawk.Emulation.Common.IEmulatorExtensions;
|
using BizHawk.Emulation.Common.IEmulatorExtensions;
|
||||||
using BizHawk.Common.BufferExtensions;
|
using BizHawk.Common.BufferExtensions;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
namespace BizHawk.Client.Common
|
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.")]
|
[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.")]
|
||||||
|
|
|
@ -6,6 +6,8 @@ using NLua;
|
||||||
|
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
|
// ReSharper disable UnusedAutoPropertyAccessor.Local
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
public sealed class MemorySavestateEmuLuaLibrary : LuaLibraryBase
|
public sealed class MemorySavestateEmuLuaLibrary : LuaLibraryBase
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using NLua;
|
using NLua;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
public sealed class MovieLuaLibrary : LuaLibraryBase
|
public sealed class MovieLuaLibrary : LuaLibraryBase
|
||||||
|
@ -176,9 +177,9 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
// Lua numbers are always double, integer precision holds up
|
// Lua numbers are always double, integer precision holds up
|
||||||
// to 53 bits, so throw an error if it's bigger than that.
|
// 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.");
|
throw new Exception("Rerecord count exceeds Lua integer precision.");
|
||||||
}
|
}
|
||||||
|
@ -208,8 +209,8 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
var movie = Global.MovieSession.Movie;
|
var movie = Global.MovieSession.Movie;
|
||||||
var system = movie.HeaderEntries[HeaderKeys.PLATFORM];
|
var system = movie.HeaderEntries[HeaderKeys.PLATFORM];
|
||||||
var pal = movie.HeaderEntries.ContainsKey(HeaderKeys.PAL) &&
|
var pal = movie.HeaderEntries.ContainsKey(HeaderKeys.PAL)
|
||||||
movie.HeaderEntries[HeaderKeys.PAL] == "1";
|
&& movie.HeaderEntries[HeaderKeys.PAL] == "1";
|
||||||
|
|
||||||
return new PlatformFrameRates()[system, pal];
|
return new PlatformFrameRates()[system, pal];
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ using BizHawk.Emulation.Common;
|
||||||
using BizHawk.Emulation.Cores.Nintendo.NES;
|
using BizHawk.Emulation.Cores.Nintendo.NES;
|
||||||
using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES;
|
using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
|
// ReSharper disable UnusedAutoPropertyAccessor.Local
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
[Description("Functions related specifically to Nes Cores")]
|
[Description("Functions related specifically to Nes Cores")]
|
||||||
|
@ -31,7 +33,7 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
private bool NESAvailable => Neshawk != null || Quicknes != null;
|
private bool NESAvailable => Neshawk != null || Quicknes != null;
|
||||||
|
|
||||||
private bool HasMemoryDOmains => MemoryDomains != null;
|
private bool HasMemoryDomains => MemoryDomains != null;
|
||||||
|
|
||||||
public NesLuaLibrary(Lua lua, Action<string> logOutputCallback)
|
public NesLuaLibrary(Lua lua, Action<string> logOutputCallback)
|
||||||
: base(lua, 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")]
|
[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)
|
public void AddGameGenie(string code)
|
||||||
{
|
{
|
||||||
if (NESAvailable && HasMemoryDOmains)
|
if (NESAvailable && HasMemoryDomains)
|
||||||
{
|
{
|
||||||
var decoder = new NESGameGenieDecoder(code);
|
var decoder = new NESGameGenieDecoder(code);
|
||||||
var watch = Watch.GenerateWatch(
|
var watch = Watch.GenerateWatch(
|
||||||
|
|
|
@ -4,6 +4,8 @@ using BizHawk.Emulation.Common;
|
||||||
using NLua;
|
using NLua;
|
||||||
using BizHawk.Emulation.Cores.Nintendo.SNES;
|
using BizHawk.Emulation.Cores.Nintendo.SNES;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
|
// ReSharper disable UnusedAutoPropertyAccessor.Local
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
[Description("Functions specific to SNESHawk (functions may not run when an SNES game is not loaded)")]
|
[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()
|
private LibsnesCore.SnesSettings GetSettings()
|
||||||
{
|
{
|
||||||
if (Snes != null)
|
return Snes != null
|
||||||
{
|
? Snes.GetSettings()
|
||||||
return Snes.GetSettings();
|
: new LibsnesCore.SnesSettings();
|
||||||
}
|
|
||||||
|
|
||||||
return new LibsnesCore.SnesSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PutSettings(LibsnesCore.SnesSettings settings)
|
private void PutSettings(LibsnesCore.SnesSettings settings)
|
||||||
|
|
|
@ -4,21 +4,21 @@ using System.ComponentModel;
|
||||||
using System.Data.SQLite;
|
using System.Data.SQLite;
|
||||||
using NLua;
|
using NLua;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
[Description("A library for performing SQLite operations.")]
|
[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) { }
|
: base(lua) { }
|
||||||
|
|
||||||
public SQLLuaLibrary(Lua lua, Action<string> logOutputCallback)
|
public SqlLuaLibrary(Lua lua, Action<string> logOutputCallback)
|
||||||
: base(lua, logOutputCallback) { }
|
: base(lua, logOutputCallback) { }
|
||||||
|
|
||||||
public override string Name => "SQL";
|
public override string Name => "SQL";
|
||||||
|
|
||||||
SQLiteConnection m_dbConnection;
|
SQLiteConnection _mDBConnection;
|
||||||
string connectionString;
|
|
||||||
|
|
||||||
[LuaMethodExample("local stSQLcre = SQL.createdatabase( \"eg_db\" );")]
|
[LuaMethodExample("local stSQLcre = SQL.createdatabase( \"eg_db\" );")]
|
||||||
[LuaMethod("createdatabase", "Creates a SQLite Database. Name should end with .db")]
|
[LuaMethod("createdatabase", "Creates a SQLite Database. Name should end with .db")]
|
||||||
|
@ -29,11 +29,10 @@ namespace BizHawk.Client.Common
|
||||||
SQLiteConnection.CreateFile(name);
|
SQLiteConnection.CreateFile(name);
|
||||||
return "Database Created Successfully";
|
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
|
try
|
||||||
{
|
{
|
||||||
SQLiteConnectionStringBuilder connBuilder = new SQLiteConnectionStringBuilder();
|
var connBuilder = new SQLiteConnectionStringBuilder
|
||||||
connBuilder.DataSource = name;
|
{
|
||||||
connBuilder.Version = 3; //SQLite version
|
DataSource = name
|
||||||
connBuilder.JournalMode = SQLiteJournalModeEnum.Wal; //Allows for reads and writes to happen at the same time
|
, Version = 3 // SQLite version
|
||||||
connBuilder.DefaultIsolationLevel = System.Data.IsolationLevel.ReadCommitted; //This only helps make the database lock left. May be pointless now
|
, JournalMode = SQLiteJournalModeEnum.Wal // Allows for reads and writes to happen at the same time
|
||||||
connBuilder.SyncMode = SynchronizationModes.Off; //This shortens the delay for do synchronous calls.
|
, DefaultIsolationLevel = System.Data.IsolationLevel.ReadCommitted // This only helps make the database lock left. May be pointless now
|
||||||
m_dbConnection = new SQLiteConnection(connBuilder.ToString());
|
, SyncMode = SynchronizationModes.Off // This shortens the delay for do synchronous calls.
|
||||||
connectionString = connBuilder.ToString();
|
};
|
||||||
m_dbConnection.Open();
|
|
||||||
m_dbConnection.Close();
|
_mDBConnection = new SQLiteConnection(connBuilder.ToString());
|
||||||
|
_mDBConnection.Open();
|
||||||
|
_mDBConnection.Close();
|
||||||
return "Database Opened Successfully";
|
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
|
try
|
||||||
{
|
{
|
||||||
m_dbConnection.Open();
|
_mDBConnection.Open();
|
||||||
string sql = query;
|
string sql = query;
|
||||||
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
|
SQLiteCommand command = new SQLiteCommand(sql, _mDBConnection);
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
m_dbConnection.Close();
|
_mDBConnection.Close();
|
||||||
|
|
||||||
return "Command ran successfully";
|
return "Command ran successfully";
|
||||||
|
|
||||||
|
@ -87,7 +88,7 @@ namespace BizHawk.Client.Common
|
||||||
}
|
}
|
||||||
catch (SQLiteException sqlEx)
|
catch (SQLiteException sqlEx)
|
||||||
{
|
{
|
||||||
m_dbConnection.Close();
|
_mDBConnection.Close();
|
||||||
return sqlEx.Message;
|
return sqlEx.Message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,9 +105,9 @@ namespace BizHawk.Client.Common
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var table = Lua.NewTable();
|
var table = Lua.NewTable();
|
||||||
m_dbConnection.Open();
|
_mDBConnection.Open();
|
||||||
string sql = $"PRAGMA read_uncommitted =1;{query}";
|
string sql = $"PRAGMA read_uncommitted =1;{query}";
|
||||||
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
|
var command = new SQLiteCommand(sql, _mDBConnection);
|
||||||
SQLiteDataReader reader = command.ExecuteReader();
|
SQLiteDataReader reader = command.ExecuteReader();
|
||||||
bool rows = reader.HasRows;
|
bool rows = reader.HasRows;
|
||||||
long rowCount = 0;
|
long rowCount = 0;
|
||||||
|
@ -124,7 +125,7 @@ namespace BizHawk.Client.Common
|
||||||
rowCount += 1;
|
rowCount += 1;
|
||||||
}
|
}
|
||||||
reader.Close();
|
reader.Close();
|
||||||
m_dbConnection.Close();
|
_mDBConnection.Close();
|
||||||
if (rows == false)
|
if (rows == false)
|
||||||
{
|
{
|
||||||
return "No rows found";
|
return "No rows found";
|
||||||
|
@ -137,12 +138,11 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
return "Database not opened.";
|
return "Database not opened.";
|
||||||
}
|
}
|
||||||
catch (SQLiteException sqlEX)
|
catch (SQLiteException sqlEx)
|
||||||
{
|
{
|
||||||
m_dbConnection.Close();
|
_mDBConnection.Close();
|
||||||
return sqlEX.Message;
|
return sqlEx.Message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||||
|
|
||||||
using NLua;
|
using NLua;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
[Description("A library exposing standard .NET string methods")]
|
[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")]
|
[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)
|
public static string Replace(string str, string str2, string replace)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(str))
|
return string.IsNullOrEmpty(str)
|
||||||
{
|
? null
|
||||||
return null;
|
: str.Replace(str2, replace);
|
||||||
}
|
|
||||||
|
|
||||||
return str.Replace(str2, replace);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LuaMethodExample("local stbiztou = bizstring.toupper( \"Some string\" );")]
|
[LuaMethodExample("local stbiztou = bizstring.toupper( \"Some string\" );")]
|
||||||
[LuaMethod("toupper", "Returns an uppercase version of the given string")]
|
[LuaMethod("toupper", "Returns an uppercase version of the given string")]
|
||||||
public static string ToUpper(string str)
|
public static string ToUpper(string str)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(str))
|
return string.IsNullOrEmpty(str)
|
||||||
{
|
? null
|
||||||
return null;
|
: str.ToUpper();
|
||||||
}
|
|
||||||
|
|
||||||
return str.ToUpper();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LuaMethodExample("local stbiztol = bizstring.tolower( \"Some string\" );")]
|
[LuaMethodExample("local stbiztol = bizstring.tolower( \"Some string\" );")]
|
||||||
[LuaMethod("tolower", "Returns an lowercase version of the given string")]
|
[LuaMethod("tolower", "Returns an lowercase version of the given string")]
|
||||||
public static string ToLower(string str)
|
public static string ToLower(string str)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(str))
|
return string.IsNullOrEmpty(str)
|
||||||
{
|
? null
|
||||||
return null;
|
: str.ToLower();
|
||||||
}
|
|
||||||
|
|
||||||
return str.ToLower();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LuaMethodExample("local stbizsub = bizstring.substring( \"Some string\", 6, 3 );")]
|
[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")]
|
[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)
|
public static string SubString(string str, int position, int length)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(str))
|
return string.IsNullOrEmpty(str)
|
||||||
{
|
? null
|
||||||
return null;
|
: str.Substring(position, length);
|
||||||
}
|
|
||||||
|
|
||||||
return str.Substring(position, length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LuaMethodExample("local stbizrem = bizstring.remove( \"Some string\", 4, 5 );")]
|
[LuaMethodExample("local stbizrem = bizstring.remove( \"Some string\", 4, 5 );")]
|
||||||
[LuaMethod("remove", "Returns a string that represents str with the given position and count removed")]
|
[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)
|
public static string Remove(string str, int position, int count)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(str))
|
return string.IsNullOrEmpty(str)
|
||||||
{
|
? null
|
||||||
return null;
|
: str.Remove(position, count);
|
||||||
}
|
|
||||||
|
|
||||||
return 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;")]
|
[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")]
|
[LuaMethod("contains", "Returns whether or not str contains str2")]
|
||||||
public static bool Contains(string str, string str2)
|
public static bool Contains(string str, string str2)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(str))
|
return !string.IsNullOrEmpty(str) && str.Contains(str2);
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str.Contains(str2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LuaMethodExample("if ( bizstring.startswith( \"Some string\", \"Some\") ) then\r\n\tconsole.log( \"Returns whether str starts with str2\" );\r\nend;")]
|
[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")]
|
[LuaMethod("startswith", "Returns whether str starts with str2")]
|
||||||
public static bool StartsWith(string str, string str2)
|
public static bool StartsWith(string str, string str2)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(str))
|
return !string.IsNullOrEmpty(str) && str.StartsWith(str2);
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str.StartsWith(str2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LuaMethodExample("if ( bizstring.endswith( \"Some string\", \"string\") ) then\r\n\tconsole.log( \"Returns whether str ends wth str2\" );\r\nend;")]
|
[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")]
|
[LuaMethod("endswith", "Returns whether str ends wth str2")]
|
||||||
public static bool EndsWith(string str, string str2)
|
public static bool EndsWith(string str, string str2)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(str))
|
return !string.IsNullOrEmpty(str) && str.EndsWith(str2);
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str.EndsWith(str2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[LuaMethodExample("local nlbizspl = bizstring.split( \"Some, string\", \", \" );")]
|
[LuaMethodExample("local nlbizspl = bizstring.split( \"Some, string\", \", \" );")]
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
|
||||||
using NLua;
|
using NLua;
|
||||||
|
|
||||||
using BizHawk.Client.Common;
|
using BizHawk.Client.Common;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
namespace BizHawk.Client.EmuHawk
|
namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
[Description("A library for setting and retrieving dynamic data that will be saved and loaded with savestates")]
|
[Description("A library for setting and retrieving dynamic data that will be saved and loaded with savestates")]
|
||||||
|
|
|
@ -23,7 +23,6 @@ namespace BizHawk.Client.Common
|
||||||
Example = example;
|
Example = example;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name { get; }
|
|
||||||
public string Example { get; }
|
public string Example { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -186,13 +186,13 @@ __Types and notation__
|
||||||
|
|
||||||
public string Example => _luaExampleAttribute?.Example;
|
public string Example => _luaExampleAttribute?.Example;
|
||||||
|
|
||||||
private string _paramterList = null;
|
private string _parameterList;
|
||||||
|
|
||||||
public string ParameterList
|
public string ParameterList
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_paramterList == null)
|
if (_parameterList == null)
|
||||||
{
|
{
|
||||||
var parameters = _method.GetParameters();
|
var parameters = _method.GetParameters();
|
||||||
|
|
||||||
|
@ -218,10 +218,10 @@ __Types and notation__
|
||||||
}
|
}
|
||||||
|
|
||||||
list.Append(')');
|
list.Append(')');
|
||||||
_paramterList = list.ToString();
|
_parameterList = list.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return _paramterList;
|
return _parameterList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
string target = $"{_currentDirectory}\\";
|
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
|
// 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?
|
// but you got any better ideas?
|
||||||
if (currDirSpeedHack == null)
|
if (currDirSpeedHack == null)
|
||||||
|
@ -117,8 +117,7 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
lock (SandboxForThread)
|
lock (SandboxForThread)
|
||||||
{
|
{
|
||||||
LuaSandbox sandbox;
|
if (SandboxForThread.TryGetValue(thread, out var sandbox))
|
||||||
if (SandboxForThread.TryGetValue(thread, out sandbox))
|
|
||||||
{
|
{
|
||||||
return sandbox;
|
return sandbox;
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,6 +193,7 @@
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=botting/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=botting/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=bsnes/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=bsnes/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bundler/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bundler/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Byteswap/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=chromeless/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=chromeless/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Coalescer/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Coalescer/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Coleco/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Coleco/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
@ -254,6 +255,7 @@
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=luaf/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=luaf/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=luases/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=luases/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mainform/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mainform/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=mainmemory/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=mame/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=mame/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mednafen/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mednafen/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Multidisk/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Multidisk/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
|
Loading…
Reference in New Issue