Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Dec 1, 2023
1 parent b0f8bb3 commit 263a882
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path> 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<String, ?> extras,
Set<Path> filesLoaded) {
Set<Path> filesLoaded, Path scriptPath) {
ExtraPlanetilerCoercions.install();
boolean luajc = arguments.getBoolean("luajc", "compile lua to java bytecode", true);
Globals globals = JsePlatform.standardGlobals();
Expand All @@ -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);
Expand All @@ -107,7 +113,7 @@ public static LuaEnvironment loadScript(Arguments arguments, String script, Stri
}

public static LuaEnvironment loadScript(Arguments args, String script, String filename, Map<String, ?> 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 {
Expand Down
4 changes: 2 additions & 2 deletions planetiler-experimental/src/test/resources/multifile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion planetiler-experimental/src/test/resources/power.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ planetiler.output.description = "Simple"
planetiler.output.attribution =
'<a href="https://www.openstreetmap.org/copyright" target="_blank">&copy;OpenStreetMap contributors</a>'
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")

Expand Down

0 comments on commit 263a882

Please sign in to comment.