allow stdlib files to use local paths for eachother

This commit is contained in:
Daniella / Tove 2024-09-19 21:29:44 +02:00
parent d4dc588c35
commit 706c4f023b
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
5 changed files with 29 additions and 20 deletions

View file

@ -1,5 +1,5 @@
"#stream.spl" import
"#net.spl" import
"stream.spl" import
"net.spl" import
"http" net:register

View file

@ -1,5 +1,5 @@
"#http.spl" import
"#server.spl" import
"../http.spl" import
"../server.spl" import
"Server" net:http:register
"server" net:http:register

View file

@ -1,4 +1,4 @@
"#stream.spl" import
"stream.spl" import
"uses less native functions where possible";

View file

@ -1,5 +1,5 @@
"#net.spl" import
"#stream.spl" import
"net.spl" import
"stream.spl" import
"server" net:register

View file

@ -616,19 +616,6 @@ pub fn import(stack: &mut Stack) -> OError {
let Value::Str(mut s) = stack.pop().lock_ro().native.clone() else {
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('#') {
s = find_in_splpath(x).unwrap_or(x.to_owned());
} else if let Some(x) = s.strip_prefix('@') {
@ -644,7 +631,29 @@ pub fn import(stack: &mut Stack) -> OError {
.to_owned()
+ "/"
+ &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(
&(*fs::canonicalize(s.clone())
.unwrap_or_else(|_| s.clone().into())