BenchmarkCore.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Lua;
  2. using MoonSharp.Interpreter;
  3. public class BenchmarkCore : IDisposable
  4. {
  5. public NLua.Lua NLuaState => nLuaState;
  6. public Neo.IronLua.LuaGlobal NeoLuaEnvironment => neoLuaEnvironment;
  7. public Script MoonSharpState => moonSharpState;
  8. public LuaState LuaCSharpState => luaCSharpState;
  9. public string FilePath => filePath;
  10. public string SourceText => sourceText;
  11. NLua.Lua nLuaState = default!;
  12. Neo.IronLua.Lua neoLuaState = default!;
  13. Neo.IronLua.LuaGlobal neoLuaEnvironment = default!;
  14. Script moonSharpState = default!;
  15. LuaState luaCSharpState = default!;
  16. string filePath = default!;
  17. string sourceText = default!;
  18. public void Setup(string fileName)
  19. {
  20. // moonsharp
  21. moonSharpState = new Script();
  22. Script.WarmUp();
  23. // NLua
  24. nLuaState = new();
  25. // NeoLua
  26. neoLuaState = new();
  27. neoLuaEnvironment = neoLuaState.CreateEnvironment();
  28. // Lua-CSharp
  29. luaCSharpState = LuaState.Create();
  30. filePath = FileHelper.GetAbsolutePath(fileName);
  31. sourceText = File.ReadAllText(filePath);
  32. }
  33. public void Dispose()
  34. {
  35. nLuaState.Dispose();
  36. neoLuaState.Dispose();
  37. }
  38. }