From 21534efd60e7ccf2d815599438a0e2b72b2d1cae Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Wed, 27 Dec 2023 13:14:46 +0200 Subject: [PATCH] feat: readd FS API via new env API --- src/me/topchetoeu/jscript/filesystem/Filesystem.java | 9 +++++++++ src/me/topchetoeu/jscript/lib/FilesystemLib.java | 7 ++----- 2 files changed, 11 insertions(+), 5 deletions(-) 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."); }