2021-03-03 15:40:19 -05:00
|
|
|
local _M = {}
|
|
|
|
|
2021-04-28 04:33:52 -04:00
|
|
|
_M.isWin = package.config:sub(1, 1) == '\\'
|
|
|
|
|
2021-03-03 15:40:19 -05:00
|
|
|
function _M.table_to_string(tbl)
|
|
|
|
local result = "{"
|
|
|
|
local keys = {}
|
|
|
|
for k in pairs(tbl) do
|
|
|
|
table.insert(keys, k)
|
|
|
|
end
|
|
|
|
table.sort(keys)
|
|
|
|
for _, k in ipairs(keys) do
|
|
|
|
local v = tbl[k]
|
|
|
|
if type(v) == "number" and v == 0 then
|
2021-03-15 16:05:02 -05:00
|
|
|
--goto continue
|
2021-03-03 15:40:19 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Check the key type (ignore any numerical keys - assume its an array)
|
|
|
|
if type(k) == "string" then
|
|
|
|
result = result.."[\""..k.."\"]".."="
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Check the value type
|
|
|
|
if type(v) == "table" then
|
2021-03-05 20:17:41 -05:00
|
|
|
result = result.._M.table_to_string(v)
|
2021-03-03 15:40:19 -05:00
|
|
|
elseif type(v) == "boolean" then
|
|
|
|
result = result..tostring(v)
|
2021-03-05 14:37:57 -05:00
|
|
|
elseif type(v) == "number" and v >= 0 then
|
|
|
|
result = result..string.format("%x", v)
|
2021-03-03 15:40:19 -05:00
|
|
|
else
|
|
|
|
result = result.."\""..v.."\""
|
|
|
|
end
|
|
|
|
result = result..",\n"
|
|
|
|
::continue::
|
|
|
|
end
|
|
|
|
-- Remove leading commas from the result
|
|
|
|
if result ~= "" then
|
|
|
|
result = result:sub(1, result:len()-1)
|
|
|
|
end
|
|
|
|
return result.."}"
|
|
|
|
end
|
|
|
|
|
|
|
|
function _M.file_exists(name)
|
|
|
|
local f=io.open(name,"r")
|
|
|
|
if f~=nil then io.close(f) return true else return false end
|
|
|
|
end
|
|
|
|
|
2021-03-05 20:17:41 -05:00
|
|
|
return _M
|