aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-06 15:39:20 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-06 15:39:20 -0400
commit6ae210f37b2b3c4c45e530109f7697a285c68fc5 (patch)
treeff766df15cece0cb5d63d984c982ec187cfcc9e7 /examples
parent594d1a627f2d731d915bacc507174347594aa7bd (diff)
Add resolve_path()
Diffstat (limited to 'examples')
-rw-r--r--examples/file.tm12
1 files changed, 12 insertions, 0 deletions
diff --git a/examples/file.tm b/examples/file.tm
index 6b8807eb..99383a56 100644
--- a/examples/file.tm
+++ b/examples/file.tm
@@ -56,6 +56,18 @@ func read(path:Text)->FileReadResult:
}
return Failure(builtin_last_err())
+func resolve_path(path:Text, relative_to=".")->Text:
+ path_c_str := path:as_c_string()
+ relative_to_c_str := relative_to:as_c_string()
+ inline C {
+ extern char *resolve_path(char*, char*, char*);
+ }
+ !! Resolving: ($path_c_str, $relative_to_c_str, $relative_to_c_str)
+ >> resolved := inline C (
+ resolve_path($path_c_str, $relative_to_c_str, $relative_to_c_str)
+ ): CString
+ return Text.from_c_string(resolved)
+
struct WriteHandle(_file:@Memory):
func write(h:WriteHandle, text:Text, flush=yes):
inline C {