chaosbot/ChaosBot/Services/ProgrammingLanguageInterpreter/LuaProgrammingLanguageInterpreter.cs

28 lines
856 B
C#

using System.Text.RegularExpressions;
using Neo.IronLua;
using NLog;
namespace ChaosBot.Services.ProgrammingLanguageInterpreter
{
internal class LuaProgrammingLanguageInterpreter : IProgrammingLanguageInterpreter
{
private static readonly ILogger Logger = Program.GetLogger();
public void Interpret(string content, string command)
{
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");
}
}
}
}
}