Mercurial Hosting > luan
changeset 1570:81288d8b20a2
add Io.relative_file_name
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 18 Nov 2020 20:41:49 -0700 |
parents | adf83ae2b9ea |
children | a23b02693d3b |
files | src/luan/modules/Boot.luan src/luan/modules/Io.luan |
diffstat | 2 files changed, 8 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/modules/Boot.luan Wed Nov 18 19:41:20 2020 -0700 +++ b/src/luan/modules/Boot.luan Wed Nov 18 20:41:49 2020 -0700 @@ -14,7 +14,6 @@ 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 = {} @@ -226,25 +225,6 @@ 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() -System.out.println(f) - 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)
--- a/src/luan/modules/Io.luan Wed Nov 18 19:41:20 2020 -0700 +++ b/src/luan/modules/Io.luan Wed Nov 18 20:41:49 2020 -0700 @@ -2,6 +2,7 @@ local IoLuan = require "java:luan.modules.IoLuan" local System = require "java:java.lang.System" local Boot = require "luan:Boot.luan" +local LuanException = require "java:luan.LuanException" local Io = {} @@ -80,6 +81,13 @@ return string_uri.read_text() end +function Io.relative_file_name(path) + local f = LuanException.getLuanStackTrace()[2].getFileName() + f = uri(f) + f.parent or error "source isn't file" + return f.parent().to_uri_string().."/"..path +end + -- debug