From 263a8824cf97786a4650526e1cc31ad418a09d74 Mon Sep 17 00:00:00 2001 From: Mike Barry Date: Thu, 30 Nov 2023 20:05:08 -0500 Subject: [PATCH] fixes --- .../experimental/lua/LuaEnvironment.java | 20 ++++++++++++------- .../src/test/resources/multifile.lua | 4 ++-- .../src/test/resources/power.lua | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/planetiler-experimental/src/main/java/com/onthegomap/planetiler/experimental/lua/LuaEnvironment.java b/planetiler-experimental/src/main/java/com/onthegomap/planetiler/experimental/lua/LuaEnvironment.java index 2bfbdba11f..98c93d7062 100644 --- a/planetiler-experimental/src/main/java/com/onthegomap/planetiler/experimental/lua/LuaEnvironment.java +++ b/planetiler-experimental/src/main/java/com/onthegomap/planetiler/experimental/lua/LuaEnvironment.java @@ -71,19 +71,21 @@ public LuaEnvironment(Planetiler runner) { } public static LuaEnvironment loadScript(Arguments arguments, Path script) throws IOException { - return loadScript(arguments, Files.readString(script), script.getFileName().toString()); + return loadScript(arguments, Files.readString(script), script.getFileName().toString(), Map.of(), + ConcurrentHashMap.newKeySet(), script); } public static LuaEnvironment loadScript(Arguments args, Path scriptPath, Set pathsToWatch) throws IOException { - return loadScript(args, Files.readString(scriptPath), scriptPath.getFileName().toString(), Map.of(), pathsToWatch); + return loadScript(args, Files.readString(scriptPath), scriptPath.getFileName().toString(), Map.of(), pathsToWatch, + scriptPath); } public static LuaEnvironment loadScript(Arguments arguments, String script, String fileName) { - return loadScript(arguments, script, fileName, Map.of(), ConcurrentHashMap.newKeySet()); + return loadScript(arguments, script, fileName, Map.of(), ConcurrentHashMap.newKeySet(), Path.of(".")); } public static LuaEnvironment loadScript(Arguments arguments, String script, String fileName, Map extras, - Set filesLoaded) { + Set filesLoaded, Path scriptPath) { ExtraPlanetilerCoercions.install(); boolean luajc = arguments.getBoolean("luajc", "compile lua to java bytecode", true); Globals globals = JsePlatform.standardGlobals(); @@ -96,8 +98,12 @@ public static LuaEnvironment loadScript(Arguments arguments, String script, Stri extras.forEach((name, java) -> globals.set(name, toLua(java))); var oldFilder = globals.finder; globals.finder = filename -> { - filesLoaded.add(Path.of(filename)); - return oldFilder.findResource(filename); + Path path = Path.of(filename); + if (!Files.exists(path)) { + path = scriptPath.resolveSibling(filename); + } + filesLoaded.add(path); + return oldFilder.findResource(path.toString()); }; globals.load(script, fileName).call(); LuaProfile profile = new LuaProfile(env); @@ -107,7 +113,7 @@ public static LuaEnvironment loadScript(Arguments arguments, String script, Stri } public static LuaEnvironment loadScript(Arguments args, String script, String filename, Map map) { - return loadScript(args, script, filename, map, ConcurrentHashMap.newKeySet()); + return loadScript(args, script, filename, map, ConcurrentHashMap.newKeySet(), Path.of(filename)); } public void run() throws Exception { diff --git a/planetiler-experimental/src/test/resources/multifile.lua b/planetiler-experimental/src/test/resources/multifile.lua index d00fa4d01f..863a203b80 100644 --- a/planetiler-experimental/src/test/resources/multifile.lua +++ b/planetiler-experimental/src/test/resources/multifile.lua @@ -7,8 +7,8 @@ planetiler.add_source('osm', { }) local layers = { - require("planetiler-experimental.src.test.resources.multifile_building"), - require("planetiler-experimental.src.test.resources.multifile_housenumber"), + require("multifile_building"), + require("multifile_housenumber"), } -- TODO make a java utility that does this in a more complete, less verbose way diff --git a/planetiler-experimental/src/test/resources/power.lua b/planetiler-experimental/src/test/resources/power.lua index cc6f14cf51..bd2f6a6649 100644 --- a/planetiler-experimental/src/test/resources/power.lua +++ b/planetiler-experimental/src/test/resources/power.lua @@ -8,7 +8,7 @@ planetiler.output.description = "Simple" planetiler.output.attribution = '©OpenStreetMap contributors' planetiler.examples = "power.spec.yaml" -planetiler.output.path = { "data", "buildings.pmtiles" } +planetiler.output.path = { "data", "power.pmtiles" } local area = planetiler.args:get_string("area", "geofabrik area to download", "massachusetts")