mudgangster

Log | Files | Refs

commit d556dd760539de03a3a234d7e99f43e98717409b
parent 5ba9d1a5d0c2ab89f63a1541d75e5ed69417e343
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Thu,  6 Sep 2018 16:40:14 +0300

Kinda fix io.readable

Diffstat:
src/lua/utils.lua | 28++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/lua/utils.lua b/src/lua/utils.lua @@ -1,3 +1,5 @@ +local lfs = require( "lfs" ) + getmetatable( "" ).__mod = function( self, form ) if type( form ) == "table" then return self:format( table.unpack( form ) ) @@ -41,17 +43,23 @@ function math.avg( a, b ) end function io.readable( path ) - -- TODO: this gives a no permissions error on windows + local attr, err = lfs.attributes( path ) + if not attr then + return false, err + end + + if attr.mode == "directory" then + return true + end + + local file, err = io.open( path, "r" ) + if not file then + return false, err + end + + io.close( file ) + return true - -- local file, err = io.open( path, "r" ) - -- - -- if not file then - -- return false, err - -- end - -- - -- io.close( file ) - -- - -- return true end function enforce( var, name, ... )