define-alpine/utils.lua

39 lines
794 B
Lua

local utils = {}
function utils.expect_nil(result)
if result then
print("Error: "..result)
os.exit(1)
end
return nil
end
-- https://stackoverflow.com/a/15278426
function utils.table_concat(t1, t2)
for i=1,#t2 do
t1[#t1+1] = t2[i]
end
return t1
end
-- Turns a table of strings into a string separated by separator.
function utils.join_table(table, separator)
local string = ""
for i=1,#table do
string = string .. table[i] .. separator
end
return string
end
-- https://github.com/Donearm/scripts/blob/ad3429dc4b69e6108f538bf1656216c7a192c9fd/lib/basename.lua
function utils.basename(str)
return string.gsub(str, "(.*/)(.*)", "%2")
end
-- https://gist.github.com/AndrewHazelden/a7b6551915a71a44770e
function utils.dirname(str)
return str:match("(.*/)")
end
return utils