diff src/luan/modules/Boot.luan @ 1568:adba594db0b4

add rel scheme
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 18 Nov 2020 17:46:16 -0700
parents b89212fd04b5
children adf83ae2b9ea
line wrap: on
line diff
--- a/src/luan/modules/Boot.luan	Sat Nov 14 20:05:07 2020 -0700
+++ b/src/luan/modules/Boot.luan	Wed Nov 18 17:46:16 2020 -0700
@@ -14,6 +14,7 @@
 local LuanUrl = require "java:luan.modules.url.LuanUrl"
 local LuanJava = require "java:luan.Luan"
 local LuanTable = require "java:luan.LuanTable"
+local LuanException = require "java:luan.LuanException"
 
 
 local Boot = {}
@@ -225,6 +226,23 @@
 end
 Boot.uri = uri
 
+local function get_caller_file()
+	for _, ste in ipairs(LuanException.getLuanStackTrace()) do
+		local f = ste.getFileName()
+		if f ~= "luan:Boot.luan" then
+			return f
+		end
+	end
+	error()
+end
+
+function schemes.rel(path)
+	local f = get_caller_file()
+	f = uri(f)
+	f.parent or error "source isn't file"
+	return f.parent().child(path)
+end
+
 
 function Boot.read(uri_str)  -- for PackageLuan.java
 	local u = uri(uri_str)