Mercurial Hosting > luan
changeset 1568:adba594db0b4
add rel scheme
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 18 Nov 2020 17:46:16 -0700 |
parents | 349eef23a13c |
children | adf83ae2b9ea |
files | src/luan/LuanException.java src/luan/modules/Boot.luan |
diffstat | 2 files changed, 22 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
diff -r 349eef23a13c -r adba594db0b4 src/luan/LuanException.java --- a/src/luan/LuanException.java Sat Nov 14 20:05:07 2020 -0700 +++ b/src/luan/LuanException.java Wed Nov 18 17:46:16 2020 -0700 @@ -91,6 +91,10 @@ return list; } + public static LuanTable getLuanStackTrace() { + return new LuanTable( justLuan( Thread.currentThread().getStackTrace() ) ); + } + public static String toLuanString(StackTraceElement ste) { int line = ste.getLineNumber(); String method = ste.getMethodName();
diff -r 349eef23a13c -r adba594db0b4 src/luan/modules/Boot.luan --- 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)