comparison 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
comparison
equal deleted inserted replaced
1567:349eef23a13c 1568:adba594db0b4
12 local matches = StringLuan.matches -- String.matches 12 local matches = StringLuan.matches -- String.matches
13 local IoLuan = require "java:luan.modules.IoLuan" 13 local IoLuan = require "java:luan.modules.IoLuan"
14 local LuanUrl = require "java:luan.modules.url.LuanUrl" 14 local LuanUrl = require "java:luan.modules.url.LuanUrl"
15 local LuanJava = require "java:luan.Luan" 15 local LuanJava = require "java:luan.Luan"
16 local LuanTable = require "java:luan.LuanTable" 16 local LuanTable = require "java:luan.LuanTable"
17 local LuanException = require "java:luan.LuanException"
17 18
18 19
19 local Boot = {} 20 local Boot = {}
20 21
21 22
223 local opener = schemes[scheme] or error( "invalid scheme '"..scheme.."' in '"..name.."'" ) 224 local opener = schemes[scheme] or error( "invalid scheme '"..scheme.."' in '"..name.."'" )
224 return opener(location,options) 225 return opener(location,options)
225 end 226 end
226 Boot.uri = uri 227 Boot.uri = uri
227 228
229 local function get_caller_file()
230 for _, ste in ipairs(LuanException.getLuanStackTrace()) do
231 local f = ste.getFileName()
232 if f ~= "luan:Boot.luan" then
233 return f
234 end
235 end
236 error()
237 end
238
239 function schemes.rel(path)
240 local f = get_caller_file()
241 f = uri(f)
242 f.parent or error "source isn't file"
243 return f.parent().child(path)
244 end
245
228 246
229 function Boot.read(uri_str) -- for PackageLuan.java 247 function Boot.read(uri_str) -- for PackageLuan.java
230 local u = uri(uri_str) 248 local u = uri(uri_str)
231 if u==nil or not u.exists() then 249 if u==nil or not u.exists() then
232 return nil 250 return nil