allow stdlib files to use local paths for eachother
This commit is contained in:
parent
d4dc588c35
commit
706c4f023b
5 changed files with 29 additions and 20 deletions
|
@ -1,5 +1,5 @@
|
||||||
"#stream.spl" import
|
"stream.spl" import
|
||||||
"#net.spl" import
|
"net.spl" import
|
||||||
|
|
||||||
"http" net:register
|
"http" net:register
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
"#http.spl" import
|
"../http.spl" import
|
||||||
"#server.spl" import
|
"../server.spl" import
|
||||||
|
|
||||||
"Server" net:http:register
|
"Server" net:http:register
|
||||||
"server" net:http:register
|
"server" net:http:register
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
"#stream.spl" import
|
"stream.spl" import
|
||||||
|
|
||||||
"uses less native functions where possible";
|
"uses less native functions where possible";
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
"#net.spl" import
|
"net.spl" import
|
||||||
"#stream.spl" import
|
"stream.spl" import
|
||||||
|
|
||||||
"server" net:register
|
"server" net:register
|
||||||
|
|
||||||
|
|
|
@ -616,19 +616,6 @@ pub fn import(stack: &mut Stack) -> OError {
|
||||||
let Value::Str(mut s) = stack.pop().lock_ro().native.clone() else {
|
let Value::Str(mut s) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("import".to_owned()));
|
return stack.err(ErrorKind::InvalidCall("import".to_owned()));
|
||||||
};
|
};
|
||||||
let fallback = s
|
|
||||||
.as_str()
|
|
||||||
.rsplit_once(|x| x == '/' || x == '#')
|
|
||||||
.map(|(.., x)| x)
|
|
||||||
.unwrap_or(s.as_str());
|
|
||||||
let fallback = runtime(|x| {
|
|
||||||
for (&p, &data) in &x.embedded_files {
|
|
||||||
if fallback == p {
|
|
||||||
return Some(data.to_owned());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
});
|
|
||||||
if let Some(x) = s.strip_prefix('#') {
|
if let Some(x) = s.strip_prefix('#') {
|
||||||
s = find_in_splpath(x).unwrap_or(x.to_owned());
|
s = find_in_splpath(x).unwrap_or(x.to_owned());
|
||||||
} else if let Some(x) = s.strip_prefix('@') {
|
} else if let Some(x) = s.strip_prefix('@') {
|
||||||
|
@ -644,7 +631,29 @@ pub fn import(stack: &mut Stack) -> OError {
|
||||||
.to_owned()
|
.to_owned()
|
||||||
+ "/"
|
+ "/"
|
||||||
+ &s;
|
+ &s;
|
||||||
|
s = s.trim_start_matches("./").to_owned();
|
||||||
}
|
}
|
||||||
|
let mut fallback = s
|
||||||
|
.as_str()
|
||||||
|
.rsplit_once(|x| x == '#')
|
||||||
|
.map(|(.., x)| x.to_owned())
|
||||||
|
.unwrap_or(s.clone());
|
||||||
|
while fallback.contains("/../") {
|
||||||
|
let mut fb = readf("{}/../{}", &fallback).unwrap();
|
||||||
|
if let Some(x) = fb[0].rsplit_once('/') {
|
||||||
|
fallback = x.0.to_owned() + &fb[1];
|
||||||
|
} else {
|
||||||
|
fallback = fb.swap_remove(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let fallback = runtime(|x| {
|
||||||
|
for (&p, &data) in &x.embedded_files {
|
||||||
|
if fallback == p {
|
||||||
|
return Some(data.to_owned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
});
|
||||||
if stack.include_file(
|
if stack.include_file(
|
||||||
&(*fs::canonicalize(s.clone())
|
&(*fs::canonicalize(s.clone())
|
||||||
.unwrap_or_else(|_| s.clone().into())
|
.unwrap_or_else(|_| s.clone().into())
|
||||||
|
|
Loading…
Add table
Reference in a new issue