diff --git a/spl/http.spl b/spl/http.spl index 410ae8d..6761982 100644 --- a/spl/http.spl +++ b/spl/http.spl @@ -1,5 +1,5 @@ -"#stream.spl" import -"#net.spl" import +"stream.spl" import +"net.spl" import "http" net:register diff --git a/spl/http/server.spl b/spl/http/server.spl index 1fd7fac..6ad36bf 100644 --- a/spl/http/server.spl +++ b/spl/http/server.spl @@ -1,5 +1,5 @@ -"#http.spl" import -"#server.spl" import +"../http.spl" import +"../server.spl" import "Server" net:http:register "server" net:http:register diff --git a/spl/pure.spl b/spl/pure.spl index f0e429f..679bf84 100644 --- a/spl/pure.spl +++ b/spl/pure.spl @@ -1,4 +1,4 @@ -"#stream.spl" import +"stream.spl" import "uses less native functions where possible"; diff --git a/spl/server.spl b/spl/server.spl index 864082e..0bd5c55 100644 --- a/spl/server.spl +++ b/spl/server.spl @@ -1,5 +1,5 @@ -"#net.spl" import -"#stream.spl" import +"net.spl" import +"stream.spl" import "server" net:register diff --git a/src/std_fns.rs b/src/std_fns.rs index 5075e1e..ea0ebac 100644 --- a/src/std_fns.rs +++ b/src/std_fns.rs @@ -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())