misc cleanups in lua code

This commit is contained in:
adelikat 2020-02-26 17:06:04 -06:00
parent b810060fcf
commit 7e741b1200
6 changed files with 16 additions and 17 deletions

View File

@ -65,7 +65,7 @@ namespace BizHawk.Client.Common
}
[LuaMethodExample("local stbizrep = bizstring.replace( \"Some string\", \"Some\", \"Replaced\" );")]
[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 occurrences of str2 in str1 with the value of replace")]
public static string Replace(string str, string str2, string replace)
{
return string.IsNullOrEmpty(str)

View File

@ -122,14 +122,9 @@ __Types and notation__
.Append(i + 1)
.Append(":");
if (parameters[i].IsOptional)
{
sb.Append($"[{parameters[i].Name}]");
}
else
{
sb.Append(parameters[i].Name);
}
sb.Append(parameters[i].IsOptional
? $"[{parameters[i].Name}]"
: parameters[i].Name);
sb.Append("}");

View File

@ -22,7 +22,7 @@ namespace BizHawk.Client.Common
protected static LuaFile CurrentFile { get; private set; }
private static Thread CurrentHostThread;
private static Thread _currentHostThread;
private static readonly object ThreadMutex = new object();
public abstract string Name { get; }
@ -33,7 +33,7 @@ namespace BizHawk.Client.Common
{
lock (ThreadMutex)
{
CurrentHostThread = null;
_currentHostThread = null;
CurrentFile = null;
}
}
@ -43,12 +43,12 @@ namespace BizHawk.Client.Common
{
lock (ThreadMutex)
{
if (CurrentHostThread != null)
if (_currentHostThread != null)
{
throw new InvalidOperationException("Can't have lua running in two host threads at a time!");
}
CurrentHostThread = Thread.CurrentThread;
_currentHostThread = Thread.CurrentThread;
CurrentFile = luaFile;
}
}

View File

@ -1,6 +1,6 @@
using System;
using System.Runtime.CompilerServices;
using BizHawk.Common;
using NLua;
// TODO - evaluate for re-entrancy problems
@ -8,7 +8,7 @@ namespace BizHawk.Client.Common
{
public unsafe class LuaSandbox
{
private static readonly System.Runtime.CompilerServices.ConditionalWeakTable<Lua, LuaSandbox> SandboxForThread = new System.Runtime.CompilerServices.ConditionalWeakTable<Lua, LuaSandbox>();
private static readonly ConditionalWeakTable<Lua, LuaSandbox> SandboxForThread = new ConditionalWeakTable<Lua, LuaSandbox>();
public static Action<string> DefaultLogger { get; set; }
@ -103,7 +103,7 @@ namespace BizHawk.Client.Common
public static LuaSandbox GetSandbox(Lua thread)
{
// this is just placeholder.
// we shouldnt be calling a sandbox with no thread--construct a sandbox properly
// we shouldn't be calling a sandbox with no thread--construct a sandbox properly
if (thread == null)
{
return new LuaSandbox();

View File

@ -950,7 +950,7 @@ namespace BizHawk.Client.EmuHawk
Filter = new FilesystemFilterSet(FilesystemFilter.LuaScripts).ToString()
};
if (sfd.ShowDialog() == DialogResult.OK)
if (sfd.ShowDialog().IsOk())
{
string text = File.ReadAllText(script.Path);
File.WriteAllText(sfd.FileName, text);

View File

@ -185,6 +185,7 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=AARRGGBB/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=accum/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=addr/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ADPCM/@EntryIndexedValue">True</s:Boolean>
@ -214,6 +215,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=bicubic/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=bilinear/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=bitshift/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=bizstring/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bizware/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=blargg/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Blit/@EntryIndexedValue">True</s:Boolean>
@ -340,6 +342,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=LSNES/@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/=Lua_0027s/@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>
@ -375,6 +378,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Oeka/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=opcode/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=opengl/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=otepad/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=outrate/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Overdump/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Overscan/@EntryIndexedValue">True</s:Boolean>