Code cleared up...

Supplement the function ExportScript.Tools.SelectModule() to determine the possible map and to send the information to Ikarus.
This commit is contained in:
mcmicha 2017-02-15 23:26:35 +01:00
parent 7b2193e753
commit fae5e59f31

View File

@ -9,80 +9,92 @@
ExportScript.Tools = {} ExportScript.Tools = {}
function ExportScript.Tools.WriteToLog(message) function ExportScript.Tools.WriteToLog(message)
if ExportScript.logFile then if ExportScript.logFile then
local ltmp, lMiliseconds = math.modf(os.clock()) local ltmp, lMiliseconds = math.modf(os.clock())
if lMiliseconds==0 then if lMiliseconds==0 then
lMiliseconds='000' lMiliseconds='000'
else else
lMiliseconds=tostring(lMiliseconds):sub(3,5) lMiliseconds=tostring(lMiliseconds):sub(3,5)
end end
ExportScript.logFile:write(os.date("%X")..":"..lMiliseconds.." : "..message.."\r\n") ExportScript.logFile:write(os.date("%X")..":"..lMiliseconds.." : "..message.."\r\n")
end end
end end
function ExportScript.Tools.ProcessInput() function ExportScript.Tools.ProcessInput()
local lCommand, lCommandArgs, lDevice local lCommand, lCommandArgs, lDevice
-- C1,3001,4 -- C1,3001,4
-- lComand = C -- lComand = C
-- lCommandArgs[1] = 1 => lDevice -- lCommandArgs[1] = 1 => lDevice
-- lCommandArgs[2] = 3001 => ButtonID -- lCommandArgs[2] = 3001 => ButtonID
-- lCommandArgs[3] = 4 => Value -- lCommandArgs[3] = 4 => Value
if ExportScript.Config.Listener then if ExportScript.Config.Listener then
local lInput,from,port = ExportScript.UDPListener:receivefrom() local lInput,from,port = ExportScript.UDPListener:receivefrom()
if ExportScript.Config.Debug then if ExportScript.Config.Debug then
ExportScript.Tools.WriteToLog("lInput: "..ExportScript.Tools.dump(lInput)..", from: "..ExportScript.Tools.dump(from)..", port: "..ExportScript.Tools.dump(port)) ExportScript.Tools.WriteToLog("lInput: "..ExportScript.Tools.dump(lInput)..", from: "..ExportScript.Tools.dump(from)..", port: "..ExportScript.Tools.dump(port))
end end
if lInput then if lInput then
lCommand = string.sub(lInput,1,1) lCommand = string.sub(lInput,1,1)
if lCommand == "R" then -- R == Reset if lCommand == "R" then -- R == Reset
if ExportScript.Config.IkarusExport then if ExportScript.Config.IkarusExport then
ExportScript.Tools.ResetChangeValues() ExportScript.Tools.ResetChangeValues()
if ExportScript.Config.Debug then
ExportScript.Tools.WriteToLog("Reset fuer Ikarus Daten")
end
end end
if ExportScript.Config.DACExport then if ExportScript.Config.DACExport then
ExportScript.Tools.ResetChangeValuesDAC() ExportScript.Tools.ResetChangeValuesDAC()
if ExportScript.Config.Debug then
ExportScript.Tools.WriteToLog("Reset fuer DAC Daten")
end
end end
end end
if (lCommand == "C") then if (lCommand == "C") then
lCommandArgs = ExportScript.Tools.StrSplit(string.sub(lInput,2),",") lCommandArgs = ExportScript.Tools.StrSplit(string.sub(lInput,2),",")
lDevice = GetDevice(lCommandArgs[1]) lDevice = GetDevice(lCommandArgs[1])
if lDevice ~= "1000" then if lDevice ~= "1000" then
if type(lDevice) == "table" then if type(lDevice) == "table" then
lDevice:performClickableAction(lCommandArgs[2],lCommandArgs[3]) lDevice:performClickableAction(lCommandArgs[2],lCommandArgs[3])
end if ExportScript.Config.Debug then
elseif lDevice == "1000" then ExportScript.Tools.WriteToLog("Verarbeite fuer Device: "..lCommandArgs[1]..", ButtonID: "..lCommandArgs[2]..", mit Wert: "..lCommandArgs[3])
--ExportScript.genericRadio(key, value) end
end
elseif lDevice == "1000" then
--ExportScript.genericRadio(key, value)
ExportScript.genericRadio(lCommandArgs[2],lCommandArgs[3]) ExportScript.genericRadio(lCommandArgs[2],lCommandArgs[3])
end if ExportScript.Config.Debug then
end ExportScript.Tools.WriteToLog("Verarbeite fuer genericRadio, ButtonID: "..lCommandArgs[2]..", mit Wert: "..lCommandArgs[3])
end end
end end
end
end
end
end end
function ExportScript.Tools.StrSplit(str, delim, maxNb) function ExportScript.Tools.StrSplit(str, delim, maxNb)
-- Eliminate bad cases... -- Eliminate bad cases...
if string.find(str, delim) == nil then if string.find(str, delim) == nil then
return { str } return { str }
end end
if maxNb == nil or maxNb < 1 then if maxNb == nil or maxNb < 1 then
maxNb = 0 -- No limit maxNb = 0 -- No limit
end end
local lResult = {} local lResult = {}
local lPat = "(.-)" .. delim .. "()" local lPat = "(.-)" .. delim .. "()"
local lNb = 0 local lNb = 0
local lLastPos local lLastPos
for part, pos in string.gfind(str, lPat) do for part, pos in string.gfind(str, lPat) do
lNb = lNb + 1 lNb = lNb + 1
lResult[lNb] = part lResult[lNb] = part
lLastPos = pos lLastPos = pos
if lNb == maxNb then break end if lNb == maxNb then break end
end end
-- Handle the last field -- Handle the last field
if lNb ~= maxNb then if lNb ~= maxNb then
lResult[lNb + 1] = string.sub(str, lLastPos) lResult[lNb + 1] = string.sub(str, lLastPos)
end end
return lResult return lResult
end end
-- remove trailing and leading whitespace from string. -- remove trailing and leading whitespace from string.
@ -129,34 +141,34 @@ end
-- Status Gathering Functions -- Status Gathering Functions
function ExportScript.Tools.ProcessArguments(device, arguments) function ExportScript.Tools.ProcessArguments(device, arguments)
local lArgument , lFormat , lArgumentValue local lArgument , lFormat , lArgumentValue
local lCounter = 0 local lCounter = 0
if ExportScript.Config.Debug then if ExportScript.Config.Debug then
ExportScript.Tools.WriteToLog("======Begin========") ExportScript.Tools.WriteToLog("======Begin========")
end end
for lArgument, lFormat in pairs(arguments) do for lArgument, lFormat in pairs(arguments) do
lArgumentValue = string.format(lFormat,device:get_argument_value(lArgument)) lArgumentValue = string.format(lFormat,device:get_argument_value(lArgument))
if ExportScript.Config.Debug then if ExportScript.Config.Debug then
lCounter = lCounter + 1 lCounter = lCounter + 1
ExportScript.Tools.WriteToLog(lCounter..". ID: "..lArgument..", Fromat: "..lFormat..", Value: "..lArgumentValue) ExportScript.Tools.WriteToLog(lCounter..". ID: "..lArgument..", Fromat: "..lFormat..", Value: "..lArgumentValue)
end end
if ExportScript.Config.IkarusExport then if ExportScript.Config.IkarusExport then
ExportScript.Tools.SendData(lArgument, lArgumentValue) ExportScript.Tools.SendData(lArgument, lArgumentValue)
end end
if ExportScript.Config.DACExport then if ExportScript.Config.DACExport then
ExportScript.Tools.SendDataDAC(lArgument, lArgumentValue) ExportScript.Tools.SendDataDAC(lArgument, lArgumentValue)
end end
end end
if ExportScript.Config.Debug then if ExportScript.Config.Debug then
ExportScript.Tools.WriteToLog("======End========") ExportScript.Tools.WriteToLog("======End========")
end end
end end
-- Network Functions for GlassCockpit -- Network Functions for GlassCockpit
function ExportScript.Tools.SendData(id, value) function ExportScript.Tools.SendData(id, value)
if id == nil then if id == nil then
ExportScript.Tools.WriteToLog("Export id is nil") ExportScript.Tools.WriteToLog("Export id is nil")
return return
@ -166,22 +178,22 @@ function ExportScript.Tools.SendData(id, value)
return return
end end
if string.len(value) > 3 and value == string.sub("-0.00000000",1, string.len(value)) then if string.len(value) > 3 and value == string.sub("-0.00000000",1, string.len(value)) then
value = value:sub(2) value = value:sub(2)
end end
if ExportScript.LastData[id] == nil or ExportScript.LastData[id] ~= value then if ExportScript.LastData[id] == nil or ExportScript.LastData[id] ~= value then
local ldata = id .. "=" .. value local ldata = id .. "=" .. value
local ldataLen = string.len(ldata) local ldataLen = string.len(ldata)
if ldataLen + ExportScript.PacketSize > 576 then if ldataLen + ExportScript.PacketSize > 576 then
ExportScript.Tools.FlushData() ExportScript.Tools.FlushData()
end end
table.insert(ExportScript.SendStrings, ldata) table.insert(ExportScript.SendStrings, ldata)
ExportScript.LastData[id] = value ExportScript.LastData[id] = value
ExportScript.PacketSize = ExportScript.PacketSize + ldataLen + 1 ExportScript.PacketSize = ExportScript.PacketSize + ldataLen + 1
end end
end end
-- Network Functions for DAC -- Network Functions for DAC
@ -213,221 +225,241 @@ function ExportScript.Tools.SendDataDAC(id, value)
end end
table.insert(ExportScript.SendStringsDAC[hardware], ldata) table.insert(ExportScript.SendStringsDAC[hardware], ldata)
ExportScript.LastDataDAC[hardware][id] = value ExportScript.LastDataDAC[hardware][id] = value
ExportScript.PacketSizeDAC[hardware] = ExportScript.PacketSizeDAC[hardware] + ldataLen + 1 ExportScript.PacketSizeDAC[hardware] = ExportScript.PacketSizeDAC[hardware] + ldataLen + 1
--ExportScript.Tools.WriteToLog("id=ldata: "..ldata) --ExportScript.Tools.WriteToLog("id=ldata: "..ldata)
--ExportScript.Tools.WriteToLog("ExportScript.LastDataDAC["..hardware.."]: "..ExportScript.Tools.dump(ExportScript.LastDataDAC[hardware])) --ExportScript.Tools.WriteToLog("ExportScript.LastDataDAC["..hardware.."]: "..ExportScript.Tools.dump(ExportScript.LastDataDAC[hardware]))
end end
end end
end end
function ExportScript.Tools.FlushData() function ExportScript.Tools.FlushData()
if #ExportScript.SendStrings > 0 then if #ExportScript.SendStrings > 0 then
local lES_SimID = "" local lES_SimID = ""
if ExportScript.GlassCockpitType == 1 then
lES_SimID = ExportScript.SimID lES_SimID = ExportScript.SimID
elseif ExportScript.GlassCockpitType == 2 then
lES_SimID = "" local lPacket = lES_SimID .. table.concat(ExportScript.SendStrings, ExportScript.Config.IkarusSeparator) .. "\n"
end ExportScript.socket.try(ExportScript.UDPsender:sendto(lPacket, ExportScript.Config.IkarusHost, ExportScript.Config.IkarusPort))
local lPacket = lES_SimID .. table.concat(ExportScript.SendStrings, ExportScript.Config.IkarusSeparator) .. "\n" ExportScript.SendStrings = {}
ExportScript.socket.try(ExportScript.UDPsender:sendto(lPacket, ExportScript.Config.IkarusHost, ExportScript.Config.IkarusPort)) ExportScript.PacketSize = 0
ExportScript.SendStrings = {} end
ExportScript.PacketSize = 0
end
end end
function ExportScript.Tools.FlushDataDAC(hardware) function ExportScript.Tools.FlushDataDAC(hardware)
hardware = hardware or 1 hardware = hardware or 1
if ExportScript.Config.DAC[hardware] == nil then if ExportScript.Config.DAC[hardware] == nil then
ExportScript.Tools.WriteToLog("unknown hardware ID '"..hardware.."'") ExportScript.Tools.WriteToLog("unknown hardware ID '"..hardware.."'")
return return
end end
if #ExportScript.SendStringsDAC[hardware] > 0 then if #ExportScript.SendStringsDAC[hardware] > 0 then
local lPacket = ExportScript.SimID .. table.concat(ExportScript.SendStringsDAC[hardware], ExportScript.Config.DAC[hardware].Separator) .. "\n" local lPacket = ExportScript.SimID .. table.concat(ExportScript.SendStringsDAC[hardware], ExportScript.Config.DAC[hardware].Separator) .. "\n"
ExportScript.socket.try(ExportScript.UDPsender:sendto(lPacket, ExportScript.Config.DAC[hardware].Host, ExportScript.Config.DAC[hardware].SendPort)) ExportScript.socket.try(ExportScript.UDPsender:sendto(lPacket, ExportScript.Config.DAC[hardware].Host, ExportScript.Config.DAC[hardware].SendPort))
ExportScript.SendStringsDAC[hardware] = {} ExportScript.SendStringsDAC[hardware] = {}
ExportScript.PacketSizeDAC[hardware] = 0 ExportScript.PacketSizeDAC[hardware] = 0
end end
end end
function ExportScript.Tools.ResetChangeValues() function ExportScript.Tools.ResetChangeValues()
ExportScript.LastData = {} ExportScript.LastData = {}
ExportScript.TickCount = 10 ExportScript.TickCount = 10
end end
function ExportScript.Tools.ResetChangeValuesDAC() function ExportScript.Tools.ResetChangeValuesDAC()
for i = 1, #ExportScript.Config.DAC, 1 do for i = 1, #ExportScript.Config.DAC, 1 do
ExportScript.LastDataDAC[i] = {} ExportScript.LastDataDAC[i] = {}
end end
ExportScript.TickCount = 10 ExportScript.TickCount = 10
ExportScript.TickCountDAC = 0 ExportScript.TickCountDAC = 0
end end
function ExportScript.Tools.SelectModule() function ExportScript.Tools.SelectModule()
-- Select Module... -- Select Module...
ExportScript.FoundDCSModule = false ExportScript.FoundDCSModule = false
ExportScript.FoundFCModule = false ExportScript.FoundFCModule = false
ExportScript.FoundNoModul = true ExportScript.FoundNoModul = true
local lMyInfo = LoGetSelfData() local lMyInfo = LoGetSelfData()
if lMyInfo == nil then -- End SelectModule, if don't selected a aircraft if lMyInfo == nil then -- End SelectModule, if don't selected a aircraft
return return
end end
ExportScript.ModuleName = lMyInfo.Name
local lModuleName = ExportScript.ModuleName..".lua"
local lModuleFile = ""
ExportScript.FoundNoModul = false
for file in lfs.dir(ExportScript.Config.ExportModulePath) do if ExportScript.Config.Debug then
if lfs.attributes(ExportScript.Config.ExportModulePath..file,"mode") == "file" then ExportScript.Tools.WriteToLog("MyInfo: "..ExportScript.Tools.dump(lMyInfo))
if file == lModuleName then end
lModuleFile = ExportScript.Config.ExportModulePath..file
end
end
end
ExportScript.Tools.WriteToLog("File Path: "..lModuleFile) ExportScript.ModuleName = lMyInfo.Name
local lModuleName = ExportScript.ModuleName..".lua"
local lModuleFile = ""
if string.len(lModuleFile) > 1 then ExportScript.FoundNoModul = false
ExportScript.Tools.ResetChangeValuesDAC()
-- load Aircraft File
dofile(lModuleFile)
ExportScript.Tools.SendDataDAC("File", lMyInfo.Name)
for i=1, #ExportScript.Config.DAC, 1 do
ExportScript.Tools.FlushDataDAC(i)
end
ExportScript.Tools.SendData("File", lMyInfo.Name)
ExportScript.Tools.FlushData()
ExportScript.Tools.WriteToLog("File '"..lModuleFile.."' loaded")
ExportScript.FirstNewDataSend = true
ExportScript.FirstNewDataSendCount = 5
if ExportScript.FoundDCSModule then for file in lfs.dir(ExportScript.Config.ExportModulePath) do
local lCounter = 0 if lfs.attributes(ExportScript.Config.ExportModulePath..file,"mode") == "file" then
for k, v in pairs(ExportScript.ConfigEveryFrameArguments) do if file == lModuleName then
lCounter = lCounter + 1 lModuleFile = ExportScript.Config.ExportModulePath..file
end end
if ExportScript.Config.Debug then end
ExportScript.Tools.WriteToLog("ExportScript.ConfigEveryFrameArguments Count: "..lCounter) end
end
if lCounter > 0 then
ExportScript.EveryFrameArguments = ExportScript.ConfigEveryFrameArguments
else
-- no Arguments
ExportScript.EveryFrameArguments = {}
end
lCounter = 0
for k, v in pairs(ExportScript.ConfigArguments) do
lCounter = lCounter + 1
end
if ExportScript.Config.Debug then
ExportScript.Tools.WriteToLog("ExportScript.ConfigArguments Count: "..lCounter)
end
if lCounter > 0 then
ExportScript.Arguments = ExportScript.ConfigArguments
else
-- no Arguments
ExportScript.Arguments = {}
end
ExportScript.ProcessIkarusDCSHighImportance = ExportScript.ProcessIkarusDCSConfigHighImportance ExportScript.Tools.WriteToLog("File Path: "..lModuleFile)
ExportScript.ProcessIkarusDCSLowImportance = ExportScript.ProcessIkarusDCSConfigLowImportance
ExportScript.ProcessDACHighImportance = ExportScript.ProcessDACConfigHighImportance
ExportScript.ProcessDACLowImportance = ExportScript.ProcessDACConfigLowImportance
elseif ExportScript.FoundFCModule then if string.len(lModuleFile) > 1 then
ExportScript.ProcessIkarusFCHighImportance = ExportScript.ProcessIkarusFCHighImportanceConfig ExportScript.Tools.ResetChangeValuesDAC()
ExportScript.ProcessIkarusFCLowImportance = ExportScript.ProcessIkarusFCLowImportanceConfig
ExportScript.ProcessDACHighImportance = ExportScript.ProcessDACConfigHighImportance -- load Aircraft File
ExportScript.ProcessDACLowImportance = ExportScript.ProcessDACConfigLowImportance dofile(lModuleFile)
else if ExportScript.Config.DACExport then
ExportScript.Tools.WriteToLog("Unknown Module Type: "..lMyInfo.Name) ExportScript.Tools.SendDataDAC("File", lMyInfo.Name)
end for i=1, #ExportScript.Config.DAC, 1 do
ExportScript.Tools.FlushDataDAC(i)
end
end
if ExportScript.Config.IkarusExport then
ExportScript.Tools.SendData("File", lMyInfo.Name)
end
else -- Unknown Module ExportScript.Tools.WriteToLog("File '"..lModuleFile.."' loaded")
ExportScript.ProcessIkarusDCSHighImportance = ExportScript.ProcessIkarusDCSHighImportanceNoConfig
ExportScript.ProcessIkarusDCSLowImportance = ExportScript.ProcessIkarusDCSLowImportanceNoConfig ExportScript.FirstNewDataSend = true
ExportScript.ProcessIkarusFCHighImportance = ExportScript.ProcessIkarusFCHighImportanceNoConfig ExportScript.FirstNewDataSendCount = 5
ExportScript.ProcessIkarusFCLowImportance = ExportScript.ProcessIkarusFCLowImportanceNoConfig
ExportScript.ProcessDACHighImportance = ExportScript.ProcessDACHighImportanceNoConfig if ExportScript.FoundDCSModule then
ExportScript.ProcessDACLowImportance = ExportScript.ProcessDACLowImportanceNoConfig local lCounter = 0
ExportScript.EveryFrameArguments = {} for k, v in pairs(ExportScript.ConfigEveryFrameArguments) do
ExportScript.Arguments = {} lCounter = lCounter + 1
ExportScript.Tools.WriteToLog("Unknown Module Name: "..lMyInfo.Name) end
end if ExportScript.Config.Debug then
ExportScript.Tools.WriteToLog("ExportScript.ConfigEveryFrameArguments Count: "..lCounter)
end
if lCounter > 0 then
ExportScript.EveryFrameArguments = ExportScript.ConfigEveryFrameArguments
else
-- no Arguments
ExportScript.EveryFrameArguments = {}
end
lCounter = 0
for k, v in pairs(ExportScript.ConfigArguments) do
lCounter = lCounter + 1
end
if ExportScript.Config.Debug then
ExportScript.Tools.WriteToLog("ExportScript.ConfigArguments Count: "..lCounter)
end
if lCounter > 0 then
ExportScript.Arguments = ExportScript.ConfigArguments
else
-- no Arguments
ExportScript.Arguments = {}
end
ExportScript.ProcessIkarusDCSHighImportance = ExportScript.ProcessIkarusDCSConfigHighImportance
ExportScript.ProcessIkarusDCSLowImportance = ExportScript.ProcessIkarusDCSConfigLowImportance
ExportScript.ProcessDACHighImportance = ExportScript.ProcessDACConfigHighImportance
ExportScript.ProcessDACLowImportance = ExportScript.ProcessDACConfigLowImportance
elseif ExportScript.FoundFCModule then
ExportScript.ProcessIkarusFCHighImportance = ExportScript.ProcessIkarusFCHighImportanceConfig
ExportScript.ProcessIkarusFCLowImportance = ExportScript.ProcessIkarusFCLowImportanceConfig
ExportScript.ProcessDACHighImportance = ExportScript.ProcessDACConfigHighImportance
ExportScript.ProcessDACLowImportance = ExportScript.ProcessDACConfigLowImportance
else
ExportScript.Tools.WriteToLog("Unknown Module Type: "..lMyInfo.Name)
end
if ExportScript.Config.IkarusExport then
for Map, LatLong in pairs(ExportScript.Maps) do
if lMyInfo.LatLongAlt.Lat > LatLong.Lat2 and lMyInfo.LatLongAlt.Lat < LatLong.Lat1 then
if lMyInfo.LatLongAlt.Long > LatLong.Long1 and lMyInfo.LatLongAlt.Long < LatLong.Long2 then
ExportScript.Tools.WriteToLog("Detected Map: "..Map)
ExportScript.Tools.SendData("Map", Map)
break
end
end
end
ExportScript.Tools.FlushData()
end
else -- Unknown Module
ExportScript.ProcessIkarusDCSHighImportance = ExportScript.ProcessIkarusDCSHighImportanceNoConfig
ExportScript.ProcessIkarusDCSLowImportance = ExportScript.ProcessIkarusDCSLowImportanceNoConfig
ExportScript.ProcessIkarusFCHighImportance = ExportScript.ProcessIkarusFCHighImportanceNoConfig
ExportScript.ProcessIkarusFCLowImportance = ExportScript.ProcessIkarusFCLowImportanceNoConfig
ExportScript.ProcessDACHighImportance = ExportScript.ProcessDACHighImportanceNoConfig
ExportScript.ProcessDACLowImportance = ExportScript.ProcessDACLowImportanceNoConfig
ExportScript.EveryFrameArguments = {}
ExportScript.Arguments = {}
ExportScript.Tools.WriteToLog("Unknown Module Name: "..lMyInfo.Name)
end
end end
-- The ExportScript.Tools.dump function show the content of the specified variable. -- The ExportScript.Tools.dump function show the content of the specified variable.
-- ExportScript.Tools.dump is similar to PHP function dump and show variables from type -- ExportScript.Tools.dump is similar to PHP function dump and show variables from type
-- "nil, "number", "string", "boolean, "table", "function", "thread" and "userdata" -- "nil, "number", "string", "boolean, "table", "function", "thread" and "userdata"
function ExportScript.Tools.dump(var, depth) function ExportScript.Tools.dump(var, depth)
depth = depth or 0 depth = depth or 0
if type(var) == "string" then if type(var) == "string" then
return 'string: "' .. var .. '"\n' return 'string: "' .. var .. '"\n'
elseif type(var) == "nil" then elseif type(var) == "nil" then
return 'nil\n' return 'nil\n'
elseif type(var) == "number" then elseif type(var) == "number" then
return 'number: "' .. var .. '"\n' return 'number: "' .. var .. '"\n'
elseif type(var) == "boolean" then elseif type(var) == "boolean" then
return 'boolean: "' .. tostring(var) .. '"\n' return 'boolean: "' .. tostring(var) .. '"\n'
elseif type(var) == "function" then elseif type(var) == "function" then
if debug and debug.getinfo then if debug and debug.getinfo then
fcnname = tostring(var) fcnname = tostring(var)
local info = debug.getinfo(var, "S") local info = debug.getinfo(var, "S")
if info.what == "C" then if info.what == "C" then
return string.format('%q', fcnname .. ', C function') .. '\n' return string.format('%q', fcnname .. ', C function') .. '\n'
else else
if (string.sub(info.source, 1, 2) == [[./]]) then if (string.sub(info.source, 1, 2) == [[./]]) then
return string.format('%q', fcnname .. ', defined in (' .. info.linedefined .. '-' .. info.lastlinedefined .. ')' .. info.source) ..'\n' return string.format('%q', fcnname .. ', defined in (' .. info.linedefined .. '-' .. info.lastlinedefined .. ')' .. info.source) ..'\n'
else else
return string.format('%q', fcnname .. ', defined in (' .. info.linedefined .. '-' .. info.lastlinedefined .. ')') ..'\n' return string.format('%q', fcnname .. ', defined in (' .. info.linedefined .. '-' .. info.lastlinedefined .. ')') ..'\n'
end end
end end
else else
return 'a function\n' return 'a function\n'
end end
elseif type(var) == "thread" then elseif type(var) == "thread" then
return 'thread\n' return 'thread\n'
elseif type(var) == "userdata" then elseif type(var) == "userdata" then
return tostring(var)..'\n' return tostring(var)..'\n'
elseif type(var) == "table" then elseif type(var) == "table" then
depth = depth + 1 depth = depth + 1
out = "{\n" out = "{\n"
for k,v in pairs(var) do for k,v in pairs(var) do
out = out .. (" "):rep(depth*4).. "["..k.."] = " .. ExportScript.Tools.dump(v, depth) out = out .. (" "):rep(depth*4).. "["..k.."] = " .. ExportScript.Tools.dump(v, depth)
end end
return out .. (" "):rep((depth-1)*4) .. "}\n" return out .. (" "):rep((depth-1)*4) .. "}\n"
else else
return tostring(var) .. "\n" return tostring(var) .. "\n"
end end
end end
-- round function for math libraray -- round function for math libraray
-- number : value -- number : value
-- decimals: number of decimal -- decimals: number of decimal
-- method : ceil: Returns the smallest integer larger than or equal to number -- method : ceil: Returns the smallest integer larger than or equal to number
-- floor: Returns the smallest integer smaller than or equal to number -- floor: Returns the smallest integer smaller than or equal to number
function ExportScript.Tools.round(number, decimals, method) function ExportScript.Tools.round(number, decimals, method)
if string.find(number, "%p" ) ~= nil then if string.find(number, "%p" ) ~= nil then
decimals = decimals or 0 decimals = decimals or 0
local lFactor = 10 ^ decimals local lFactor = 10 ^ decimals
if (method == "ceil" or method == "floor") then if (method == "ceil" or method == "floor") then
-- ceil: Returns the smallest integer larger than or equal to number -- ceil: Returns the smallest integer larger than or equal to number
-- floor: Returns the smallest integer smaller than or equal to number -- floor: Returns the smallest integer smaller than or equal to number
return math[method](number * lFactor) / lFactor return math[method](number * lFactor) / lFactor
else else
return tonumber(("%."..decimals.."f"):format(number)) return tonumber(("%."..decimals.."f"):format(number))
end end
else else
return number return number
end end
end end
-- split function for string libraray -- split function for string libraray
@ -435,11 +467,11 @@ end
-- delimiter : delimiter for split -- delimiter : delimiter for split
-- for example, see http://www.lua.org/manual/5.1/manual.html#5.4.1 -- for example, see http://www.lua.org/manual/5.1/manual.html#5.4.1
function ExportScript.Tools.split(stringvalue, delimiter) function ExportScript.Tools.split(stringvalue, delimiter)
result = {}; result = {};
for match in (stringvalue..delimiter):gmatch("(.-)"..delimiter) do for match in (stringvalue..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match); table.insert(result, match);
end end
return result; return result;
end end
-- the function evaluation of the handover parameters and makes accordingly to the light on or off -- the function evaluation of the handover parameters and makes accordingly to the light on or off