luaext.lua

changeset 35
2f927eae429b
parent 3
b2df1b3f2c83
--- a/luaext.lua	Sun Sep 06 21:24:39 2020 +0300
+++ b/luaext.lua	Sun Sep 06 22:12:52 2020 +0300
@@ -6,6 +6,8 @@
 -- See the included file LICENSE for details.
 --
 
+local lfs=require("lfs")
+local path=require("mypath")
 
 --DOC
 -- Make \var{str} shell-safe.
@@ -87,8 +89,15 @@
     end
 end
 
-function io.openX(file, ...)
-    local f, err = io.open(file, ...)
+function io.openX(file, mode)
+    if mode=='w' then
+        local dn = path.dirname(file)
+        if not lfs.attributes(dn) then
+            print("Ensure directory", dn)
+            lfs.mkdir(dn)
+        end
+    end
+    local f, err = io.open(file, mode)
     if not f then
         error(file..": "..err)
     end

mercurial