ExperimentalGear/scripts/api/platform.lua

48 lines
1.0 KiB
Lua
Raw Normal View History

2024-02-02 02:27:05 +01:00
require "common.globals"
require "api.logging"
---@note setup code from: https://stackoverflow.com/a/30960054
2024-02-02 02:27:05 +01:00
local BinaryFormat = package.cpath:match("%?%.(%a+)")
DetailedLog("BinaryFormat: " .. BinaryFormat, game.LOGGER_DEBUG)
if BinaryFormat == "dll" then
function os.name()
return "Windows"
end
elseif BinaryFormat == "so" then
function os.name()
return "Linux"
end
elseif BinaryFormat == "dylib" then
function os.name()
return "MacOS"
end
2024-02-02 02:27:05 +01:00
else
DetailedLog("Could not identify binary format", game.LOGGER_WARNING)
function os.name()
return nil
end
end
BinaryFormat = nil
Platform = {
WINDOWS = "Windows",
LINUX = "Linux",
MACOS = "MacOS"
}
---Get OS platform lua is running on
function GetPlatform()
return os.name()
end
---Merge base module table with implementation table, overwriting base
---@param base any
---@param implementation any
function MergeModules(base, implementation)
for key, value in pairs(implementation) do
base[key] = value
end
end