summary refs log tree commit diff stats
path: root/src/host
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2024-05-29 23:00:53 -0300
committerSoniEx2 <endermoneymod@gmail.com>2024-05-29 23:00:53 -0300
commit5eecbd6ef771a54b455d96f4033212062d7c3f8f (patch)
tree9fef3d210df849e82baa763b8b2b885c4806ca96 /src/host
parentbbb9f04eecc66a9e8e208cc4abc0466697807765 (diff)
Implement cratera bootstrap
Diffstat (limited to 'src/host')
-rw-r--r--src/host/genpath.lua25
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)))