diff options
Diffstat (limited to 'src/host')
-rw-r--r-- | src/host/genpath.lua | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/host/genpath.lua b/src/host/genpath.lua new file mode 100644 index 0000000..e12e9a8 --- /dev/null +++ b/src/host/genpath.lua @@ -0,0 +1,25 @@ +-- generate default cratera path +-- package.path, but every .lua is replaced with .cratera +-- or use an explicit CRATERA_PATH + +if os.getenv("DEFAULT_CRATERA_PATH") then + print(string.format("return %q", os.getenv("DEFAULT_CRATERA_PATH"))) + return +end + +local pathsep = package.config:match("^[^\n]+\n([^\n]+)") +local pathfinder = "[^"..pathsep.."]*" +-- not gonna worry about ".lua.lua" tbh... +local possible_cratera_path = package.path:gsub("%.lua(.)", {[pathsep] = ".cratera" .. pathsep}):gsub("%.lua$",".cratera") +local path_parts = {} +local i = 1 +-- path entries to skip based on filename +local INIT_FILE = "init.cratera" +for path_part in possible_cratera_path:gmatch(pathfinder) do + if not path_part:find(INIT_FILE, -#INIT_FILE, true) then + path_parts[i] = path_part + i = i + 1 + end +end + +print(string.format("return %q", table.concat(path_parts, pathsep))) |