
local Utils = {}

function Utils:GetScriptNameByScriptPath(scriptPath)
	local startIndex = string.find(scriptPath, "%a+.lua")
	local endIndex = string.find(scriptPath, ".lua") - 1
	local scriptName = string.sub(scriptPath, startIndex, endIndex)
	
	return scriptName
end

function Utils:OutputLuaTable(tData, szPrefix)
	if not szPrefix then szPrefix = "" end
    for _, v in pairs(tData) do
		if type(v) == "table" then
            Utils:OutputLuaTable(v, "\t")
        end
    end
end

function Utils:Table2String(tab, csp)
    local parentOffset = csp or ""
    local propertyOffset = parentOffset .. "\t"
    local str = ""
    str = str .. "{" .. "\n"
    for k, v in pairs(tab) do
         if type(v)=="table" then
             str = str .. propertyOffset.. k .. " = " .. Utils:Table2String(v, propertyOffset) .. ",\n"
         else
             str = str .. propertyOffset.. k .. " = '" .. v .. "',\n"
         end
    end
    str = string.sub(str, 1, string.len(str) - string.len(",\n")) .. "\n"
    str = str .. parentOffset .. "}"
    return str
end

function Utils:TableDeepCopy(tSrcTable)      
    local tSearchTable = {}  

    local function _copy(tSrcTable)  
        if type(tSrcTable) ~= "table" then  
            return tSrcTable         
        end  
        local tNewTable = {}  
        tSearchTable[tSrcTable] = tNewTable  
        for k, v in pairs(tSrcTable) do  
            tNewTable[_copy(k)] = _copy(v)  
        end     
       
        return setmetatable(tNewTable, getmetatable(tSrcTable))      
    end    
  
    return _copy(tSrcTable)  
end 

function Utils:TimeNow()
    local nTimeNow = os.time()
    local szTimeFormat = os.date("%Y-%m-%d %H:%M:%S", nTimeNow)
    return nTimeNow, szTimeFormat
end

function Utils:FormatHMS(nTime)
    local nHour     = 0
    local nMin      = 0
    local nSecond   = 0

    nHour = math.floor(nTime / 3600)
    nMin  = math.floor((nTime - nHour * 3600) / 60)
    nSecond = math.floor(nTime % 60)

    local szTime = ""
	szTime = szTime .. string.format("%02d:", nHour) 
	szTime = szTime .. string.format("%02d:", nMin) 
	szTime = szTime .. string.format("%02d", nSecond) 

    return szTime
end
return Utils