JD2022-TU1/main/tools/framework/JD.Serialization/helpers.ilu

89 lines
1.5 KiB
Text

TRUE = 1
FALSE = 0
function math.round(x)
return math.floor(x + 0.5)
end
function getValue(a,default)
if a == nil then
return default
else
return a
end
end
function appendTable(a,b)
table.foreach(b,
function(x,y)
if type(y) == "table" then
y.__TablePath = ITF_LocalFile
end
table.insert(a,y)
end)
end
function getTable(path)
TABLE = nil
includeReference(path)
local tabIn = TABLE
TABLE = nil
if tabIn == nil or type(tabIn) ~= "table" then
return nil
end
tabIn.__TablePath = path
return tabIn
end
function getTableList(path)
TABLELIST = nil
includeReference(path)
local tabListIn = TABLELIST
TABLELIST = nil
if tabListIn == nil or type(tabListIn) ~= "table" or #tabListIn == 0 then
return nil
end
tabListIn.__ExpandedPath = path
return tabListIn
end
function getExpandedTable(tab)
if type(tab) ~= "table" then
return tab
end
local newTab = {}
local tabIdxLen = #tab
if tabIdxLen > 0 then -- table indexed
for i=1, tabIdxLen do
local tIn = tab[i]
if type(tIn) == "table" and tIn.__ExpandedPath then
for j=1, #tIn do
local tInIn = tIn[j]
tInIn.__TableListPath = tIn.__ExpandedPath
table.insert(newTab, getExpandedTable(tInIn))
end
else
table.insert(newTab, getExpandedTable(tIn))
end
end
end
for k, v in pairs(tab) do
if type(k) ~= "number" then
newTab[k] = getExpandedTable(v)
end
end
return newTab
end
function ExpandTable(tabName)
_G[tabName] = getExpandedTable(_G[tabName])
end