Add io compatibility layer

....I can't believe that Lua doesn't have an inbuilt scandir 
equivalent?!
This commit is contained in:
Starbeamrainbowlabs 2021-12-31 00:57:17 +00:00
parent 1e9a651537
commit f259f85771
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2
3 changed files with 18 additions and 1 deletions

@ -18,6 +18,9 @@ wea.Queue = dofile(wea.modpath.."/utils/queue.lua")
wea.LRU = dofile(wea.modpath.."/utils/lru.lua") wea.LRU = dofile(wea.modpath.."/utils/lru.lua")
wea.inspect = dofile(wea.modpath.."/utils/inspect.lua") wea.inspect = dofile(wea.modpath.."/utils/inspect.lua")
-- I/O compatibility layer
wea.io = dofile(wea.modpath.."/utils/io.lua")
wea.bit = dofile(wea.modpath.."/utils/bit.lua") wea.bit = dofile(wea.modpath.."/utils/bit.lua")

@ -0,0 +1,14 @@
local io = {
-- Ref https://minetest.gitlab.io/minetest/minetest-namespace-reference/#utilities
scandir = function(dirpath)
return minetest.get_dir_list(dirpath, nil)
end,
scandir_files = function(dirpath)
return minetest.get_dir_list(dirpath, false)
end,
scandir_dirs = function(dirpath)
return minetest.get_dir_list(dirpath, true)
end,
}
return io