Skip to content

Commit

Permalink
Lua: Remove write() function
Browse files Browse the repository at this point in the history
It can be implemented using standard lua
  • Loading branch information
dennis committed Dec 23, 2020
1 parent e5eff16 commit c1d427d
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions Backend/Plugins/LuaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void StartLua()

try
{
Api = new LuaApi(EventBus, StateService, Path.GetFileName(FilePath), Path.GetDirectoryName(FilePath));
Api = new LuaApi(EventBus, StateService, Path.GetFileName(FilePath));
Lua = new Lua();

DisplayName = "Lua: " + Path.GetFileName(FilePath);
Expand All @@ -56,7 +56,6 @@ private void StartLua()
Lua.RegisterFunction("play", Api, typeof(LuaApi).GetMethod("Play", new[] { typeof(string), typeof(float) }));
Lua.RegisterFunction("debounce", Api, typeof(LuaApi).GetMethod("Debounce", new[] { typeof(string), typeof(LuaFunction), typeof(float) }));
Lua.RegisterFunction("wait", Api, typeof(LuaApi).GetMethod("Wait", new[] { typeof(string), typeof(LuaFunction), typeof(float) }));
Lua.RegisterFunction("write", Api, typeof(LuaApi).GetMethod("Write", new[] { typeof(string), typeof(string) }));
Lua.RegisterFunction("send_twitch_message", Api, typeof(LuaApi).GetMethod("SendTwitchMessage", new[] { typeof(string) }));
Lua.RegisterFunction("set_state", Api, typeof(LuaApi).GetMethod("SetState", new[] { typeof(string), typeof(string) }));
Lua.RegisterFunction("set_temp_state", Api, typeof(LuaApi).GetMethod("SetTempState", new[] { typeof(string), typeof(string), typeof(int) }));
Expand Down Expand Up @@ -100,7 +99,6 @@ class LuaApi
private readonly string Prefix;
private readonly IDictionary<string, DelayedExecution> DebouncedFunctions = new Dictionary<string, DelayedExecution>();
private readonly IDictionary<string, DelayedExecution> WaitingFunctions = new Dictionary<string, DelayedExecution>();
private readonly string WorkDirectory;
private readonly IStateService StateService;

private class DelayedExecution
Expand All @@ -115,11 +113,10 @@ public DelayedExecution(LuaFunction luaFunction, DateTime triggersAt)
}
}

public LuaApi(IEventBus eventBus, IStateService stateService, string prefix, string workDirectory)
public LuaApi(IEventBus eventBus, IStateService stateService, string prefix)
{
EventBus = eventBus;
Prefix = prefix;
WorkDirectory = workDirectory;
StateService = stateService;
}

Expand Down Expand Up @@ -183,19 +180,6 @@ public void Wait(string name, LuaFunction func, float duration)
}
}

public void Write(string filePath, string content)
{
string fileDirectory = Path.GetDirectoryName(filePath);

if(fileDirectory.Length == 0)
{
filePath = WorkDirectory + @"\" + filePath;
}

using StreamWriter sw = File.AppendText(filePath);
sw.Write(content);
}

private void HandleDelayedExecution(IDictionary<string, DelayedExecution> functions)
{
string? deleteKey = null;
Expand Down

0 comments on commit c1d427d

Please sign in to comment.