mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-09 00:43:48 +01:00
Add io compatibility layer
....I can't believe that Lua doesn't have an inbuilt scandir equivalent?!
This commit is contained in:
parent
1e9a651537
commit
f259f85771
@ -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")
|
||||||
|
|
||||||
|
|
||||||
|
14
worldeditadditions/utils/io.lua
Normal file
14
worldeditadditions/utils/io.lua
Normal file
@ -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
|
@ -62,7 +62,7 @@ end
|
|||||||
-- @param plain boolean If true (or truthy), pattern is interpreted as a
|
-- @param plain boolean If true (or truthy), pattern is interpreted as a
|
||||||
-- plain string, not a Lua pattern
|
-- plain string, not a Lua pattern
|
||||||
-- @returns table A sequence table containing the substrings
|
-- @returns table A sequence table containing the substrings
|
||||||
function worldeditadditions.split (str,dlm,plain)
|
function worldeditadditions.split(str,dlm,plain)
|
||||||
local pos, ret = 0, {}
|
local pos, ret = 0, {}
|
||||||
local ins, i = str:find(dlm,pos,plain)
|
local ins, i = str:find(dlm,pos,plain)
|
||||||
-- "if plain" shaves off some time in the while statement
|
-- "if plain" shaves off some time in the while statement
|
||||||
|
Loading…
Reference in New Issue
Block a user