summary refs log blame commit diff stats
path: root/src/host/genpath.lua
blob: e12e9a8aa10abbbe14e7ff444d2092ccde6b5298 (plain) (tree)
























                                                                                                                          
-- 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)))