Debian Codegraph @

texmf-dist/doc/support/cluttex/src/fs-util.sml

raw
1 structure FSUtil : sig
2 val copyCommand : { from : string, to : string } -> string
3 val isFile : string -> bool
4 val isDirectory : string -> bool
5 val mkDirRec : string -> unit
6 val removeRec : string -> unit
7 val touch : string -> unit
8 end = struct
9 val lfs = LunarML.assumeDiscardable (fn () => Lua.call1 Lua.Lib.require #[Lua.fromString "lfs"]) ()
10 val luamod = LunarML.assumeDiscardable (fn () => Lua.call1 Lua.Lib.require #[Lua.fromString "texrunner.fsutil"]) ()
11 fun copyCommand { from, to } : string = Lua.unsafeFromValue (Lua.call1 (Lua.field (luamod, "copy_command")) #[Lua.fromString from, Lua.fromString to])
12 val isFile : string -> bool = LunarML.assumeDiscardable (fn () => Lua.unsafeFromValue (Lua.field (luamod, "isfile"))) ()
13 val isDirectory : string -> bool = LunarML.assumeDiscardable (fn () => Lua.unsafeFromValue (Lua.field (luamod, "isdir"))) ()
14 fun mkDirRec path = let val (succ, err) = Lua.call2 (Lua.field (luamod, "mkdir_rec")) #[Lua.fromString path]
15 in if Lua.isFalsy succ then
16 raise Lua.Error err
17 else
18 ()
19 end
20 fun removeRec path = let val (succ, err) = Lua.call2 (Lua.field (luamod, "remove_rec")) #[Lua.fromString path]
21 in if Lua.isFalsy succ then
22 raise Lua.Error err
23 else
24 ()
25 end
26 fun touch path = let val (succ, err) = Lua.call2 (Lua.field (lfs, "touch")) #[Lua.fromString path]
27 in if Lua.isFalsy succ then
28 raise Lua.Error err
29 else
30 ()
31 end
32 end;