Export realtime game statistics to disk in JSON and other formats.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.3 KiB

-- ___ _ _ _
-- / __| |_ __ _| |_ ___ _ _(_)___
-- \__ \ _/ _` | _/ _ \ '_| / _ \
-- |___/\__\__,_|\__\___/_| |_\___/
--
--
-- Collect statistics from Factorio
-- game APIs and write them to disk
-- in JSON for consumption in other
-- dashboard software or something.
--
-- General utility functions
function split(str, character)
result = {}
index = 1
if str == nil then return result end
if character == nil then return result end
for s in string.gmatch(str, "[^"..character.."]+") do
result[index] = s
index = index + 1
end
return result
end
function safeString(val)
if type(val) == "string" then return val end
if type(val) == "number" then return val end
if type(val) == "boolean" then
if (val) then return "true" else return "false" end
end
return "nil"
end
function checkTableKeyExists(tableName, needle)
res, data = pcall(function() return tableName[needle] end)
if res and data ~= nil then return true end
if tonumber(needle) ~= nil and table_size(tableName) <= tonumber(needle) then return true end
return false
end
function isNumeric(x)
if tonumber(x) ~= nil then
return true
end
return false
end
function get_file_extension(path)
parts = split(path, ".")
return parts[#parts]
end