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.
52 lines
1.2 KiB
52 lines
1.2 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 |