FileModuleLoader.cs 574 B

12345678910111213141516171819
  1. namespace Lua.Loaders;
  2. public sealed class FileModuleLoader : ILuaModuleLoader
  3. {
  4. public static readonly FileModuleLoader Instance = new();
  5. public bool Exists(string moduleName)
  6. {
  7. return File.Exists(moduleName);
  8. }
  9. public async ValueTask<LuaModule> LoadAsync(string moduleName, CancellationToken cancellationToken = default)
  10. {
  11. var path = moduleName;
  12. if (!Path.HasExtension(path)) path += ".lua";
  13. var text = await File.ReadAllBytesAsync(path, cancellationToken);
  14. return new LuaModule(moduleName, text);
  15. }
  16. }