Get basic Lua interpreter set up
This commit is contained in:
parent
0636205e05
commit
ebbf2c858a
@ -16,6 +16,7 @@
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.6" />
|
||||
<PackageReference Include="NeoLua" Version="1.3.11" />
|
||||
<PackageReference Include="NLog" Version="4.7.2" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.4" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.2" />
|
||||
|
||||
@ -2,6 +2,7 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ChaosBot.Models;
|
||||
using ChaosBot.Services.ProgrammingLanguageInterpreter;
|
||||
using Discord.Commands;
|
||||
|
||||
namespace ChaosBot.Discord.Services
|
||||
@ -30,7 +31,8 @@ namespace ChaosBot.Discord.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException($"No support for command type ${customCommand.Type}");
|
||||
if (!ProgrammingLanguageInterpreterFacade.TryInterpret(customCommand))
|
||||
throw new NotImplementedException($"No support for command type ${customCommand.Type}");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@ -2,6 +2,6 @@ namespace ChaosBot.Services.ProgrammingLanguageInterpreter
|
||||
{
|
||||
public interface IProgrammingLanguageInterpreter
|
||||
{
|
||||
void Interpret(string content);
|
||||
void Interpret(string content, string command);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using Neo.IronLua;
|
||||
using NLog;
|
||||
|
||||
namespace ChaosBot.Services.ProgrammingLanguageInterpreter
|
||||
@ -7,9 +8,20 @@ namespace ChaosBot.Services.ProgrammingLanguageInterpreter
|
||||
{
|
||||
private static readonly ILogger Logger = Program.GetLogger();
|
||||
|
||||
public void Interpret(string content)
|
||||
public void Interpret(string content, string command)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using (Lua lua = new Lua())
|
||||
{
|
||||
// This needs to be dynamic if we want to call
|
||||
// functions from within the lua environment
|
||||
// This is a runtime type check
|
||||
dynamic env = lua.CreateEnvironment();
|
||||
|
||||
foreach (string line in (new Regex("\n")).Split(content))
|
||||
{
|
||||
env.dochunk(line, $"{command}.lua");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,12 +4,14 @@ namespace ChaosBot.Services.ProgrammingLanguageInterpreter
|
||||
{
|
||||
public static class ProgrammingLanguageInterpreterFacade
|
||||
{
|
||||
public static void Interpret(CustomCommand customCommand)
|
||||
public static bool TryInterpret(CustomCommand customCommand)
|
||||
{
|
||||
IProgrammingLanguageInterpreter interpreter =
|
||||
ProgrammingLanguageInterpreterFactory.GetInterpreter(customCommand.Type);
|
||||
if (interpreter == null) return false;
|
||||
|
||||
interpreter.Interpret(customCommand.Content);
|
||||
interpreter.Interpret(customCommand.Content, customCommand.Command);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ namespace ChaosBot.Services.ProgrammingLanguageInterpreter
|
||||
case CustomCommandType.CustomLua:
|
||||
return new LuaProgrammingLanguageInterpreter();
|
||||
default:
|
||||
return new LuaProgrammingLanguageInterpreter();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user