diff --git a/src/me/topchetoeu/jscript/filesystem/Filesystem.java b/src/me/topchetoeu/jscript/filesystem/Filesystem.java index c21fb9e..2ac5e75 100644 --- a/src/me/topchetoeu/jscript/filesystem/Filesystem.java +++ b/src/me/topchetoeu/jscript/filesystem/Filesystem.java @@ -1,8 +1,17 @@ package me.topchetoeu.jscript.filesystem; +import me.topchetoeu.jscript.engine.Extensions; +import me.topchetoeu.jscript.engine.values.Symbol; + public interface Filesystem { + public static final Symbol ENV_KEY = Symbol.get("Environment.fs"); + String normalize(String... path); File open(String path, Mode mode) throws FilesystemException; void create(String path, EntryType type) throws FilesystemException; FileStat stat(String path) throws FilesystemException; + + public static Filesystem get(Extensions exts) { + return exts.get(ENV_KEY); + } } \ No newline at end of file diff --git a/src/me/topchetoeu/jscript/lib/FilesystemLib.java b/src/me/topchetoeu/jscript/lib/FilesystemLib.java index 881f5ad..2d3f62e 100644 --- a/src/me/topchetoeu/jscript/lib/FilesystemLib.java +++ b/src/me/topchetoeu/jscript/lib/FilesystemLib.java @@ -25,11 +25,8 @@ public class FilesystemLib { @Native public static final int SEEK_END = 2; private static Filesystem fs(Context ctx) { - var env = ctx.environment(); - if (env != null) { - var fs = ctx.environment().filesystem; - if (fs != null) return fs; - } + var fs = Filesystem.get(ctx); + if (fs != null) return fs; throw EngineException.ofError("Current environment doesn't have a file system."); }