diff --git a/src/conf.lua b/src/conf.lua index ea28ce38..426f7dbd 100644 --- a/src/conf.lua +++ b/src/conf.lua @@ -1,6 +1,13 @@ +require("lua_setup") + +local meta = require("meta") +local configs = require("configs") +local persistence = require("persistence") + function love.conf(t) t.console = true + t.title = meta.title t.window.resizable = true t.window.minwidth = 1280 t.window.width = 1280 diff --git a/src/configs.lua b/src/configs.lua index 977404fc..e2c9d76f 100644 --- a/src/configs.lua +++ b/src/configs.lua @@ -5,7 +5,7 @@ local utils = require("utils") local config = require("utils.config") local fileLocations = require("file_locations") -local defaultsPath = "defaults/config" +local defaultsPath = "defaults.config" local defaultValues = {} local configs = config.readConfig(fileLocations.getSettingsPath()) diff --git a/src/file_locations.lua b/src/file_locations.lua index e9ba4e3f..f9305eb8 100644 --- a/src/file_locations.lua +++ b/src/file_locations.lua @@ -1,5 +1,6 @@ local filesystem = require("utils.filesystem") local config = require("utils.config") +local utils = require("utils") local fileLocations = {} @@ -9,7 +10,7 @@ fileLocations.loennLinuxFolderName = "Lönn" fileLocations.loennZipFolderName = "L" .. string.char(148) .. "nn" function fileLocations.getStorageDir() - local userOS = love.system.getOS() + local userOS = utils.getOS() local windowsFolderName = fileLocations.loennWindowsFolderName local linuxFolderName = fileLocations.loennLinuxFolderName diff --git a/src/lua_setup.lua b/src/lua_setup.lua new file mode 100644 index 00000000..84c08f96 --- /dev/null +++ b/src/lua_setup.lua @@ -0,0 +1,24 @@ +-- Setting up globals for a new Lua environment (main.lua or conf.lua) + +local ffi = require("ffi") + +local path = "selene/selene/lib/?.lua;selene/selene/lib/?/init.lua;?/?.lua;" .. love.filesystem.getRequirePath() +love.filesystem.setRequirePath(path) + +-- love.system might not exist yet +if ffi and ffi.os == "OSX" then + package.cpath = package.cpath .. ";" .. love.filesystem.getSourceBaseDirectory() .. "/?.so" +end + +-- Load faster unpack function +require("lib.fast_unpack") + +-- Keeping it here since it is an option, and seems to make a difference at some points +-- Attempt to expose to config option at some point +--[[ +_G._selene = {} +_G._selene.notypecheck = true +]] + +require("selene").load() +require("selene/selene/wrappers/searcher/love2d/searcher").load() \ No newline at end of file diff --git a/src/main.lua b/src/main.lua index 54aee3ba..45c8fb4f 100644 --- a/src/main.lua +++ b/src/main.lua @@ -1,25 +1,5 @@ function love.load() - local path = "selene/selene/lib/?.lua;selene/selene/lib/?/init.lua;?/?.lua;" .. love.filesystem.getRequirePath() - love.filesystem.setRequirePath(path) - - -- The English language contains over 500,000 words and not a single one of them is suitable for describing just how much I want to purge macos from existence. - if love.system.getOS() == "OS X" then - package.cpath = package.cpath .. ";" .. love.filesystem.getSourceBaseDirectory() .. "/?.so" - end - - -- Load faster unpack function - require("lib.fast_unpack") - - -- Keeping it here since it is an option, and seems to make a difference at some points - -- Attempt to expose to config option at some point - --[[ - _G._selene = {} - _G._selene.notypecheck = true - ]] - - require("selene").load() - require("selene/selene/wrappers/searcher/love2d/searcher").load() - + require("lua_setup") require("selene_main") end diff --git a/src/selene_main.lua b/src/selene_main.lua index 6f30079f..05d36005 100644 --- a/src/selene_main.lua +++ b/src/selene_main.lua @@ -1,9 +1,6 @@ -- love.load() is not called again, put stuff here. local logging = require("logging") -local meta = require("meta") - -love.window.setTitle(meta.title) love.keyboard.setKeyRepeat(true) diff --git a/src/utils/filesystem.lua b/src/utils/filesystem.lua index 9f1755a4..d9848a6e 100644 --- a/src/utils/filesystem.lua +++ b/src/utils/filesystem.lua @@ -8,7 +8,9 @@ local hasRequest, request = requireUtils.tryrequire("lib.luajit-request.luajit-r local filesystem = {} -filesystem.supportWindowsInThreads = love.system.getOS() ~= "OS X" +function filesystem.supportWindowsInThreads() + return love.system.getOS() ~= "OS X" +end function filesystem.filename(path, sep) sep = sep or physfs.getDirSeparator() @@ -176,7 +178,7 @@ function filesystem.saveDialog(path, filter, callback) -- TODO - Verify arguments, documentation was very existant if callback then - if filesystem.supportWindowsInThreads then + if filesystem.supportWindowsInThreads() then local code = [[ local args = {...} local channelName, path, filter = unpack(args) @@ -207,7 +209,7 @@ function filesystem.openDialog(path, filter, callback) -- TODO - Verify arguments, documentation was very existant if callback then - if filesystem.supportWindowsInThreads then + if filesystem.supportWindowsInThreads() then local code = [[ local args = {...} local channelName, path, filter = unpack(args) diff --git a/src/utils/utils.lua b/src/utils/utils.lua index 9e57b489..a45a9b88 100644 --- a/src/utils/utils.lua +++ b/src/utils/utils.lua @@ -3,6 +3,7 @@ local filesystem = require("utils.filesystem") local requireUtils = require("utils.require") local xnaColors = require("consts.xna_colors") local bit = require("bit") +local ffi = require("ffi") local rectangles = require("structs.rectangle") @@ -677,6 +678,22 @@ function utils.round(n, decimals) end end +-- ffi to love.system names +local ffiOSLookup = { + Windows = "Windows", + Linux = "Linux", + OSX = "OS X" +} + +function utils.getOS() + if love.system then + return love.system.getOS() + end + + -- Fallback to ffi.os, some names differ but it is good enough + return ffiOSLookup[ffi.os] +end + -- Add all of require utils into utils for k, v <- requireUtils do utils[k] = v @@ -689,7 +706,7 @@ for k, v <- filesystem do end -- Add filesystem specific helper methods -local osFilename = love.system.getOS():lower():gsub(" ", "_") +local osFilename = utils.getOS():lower():gsub(" ", "_") local hasOSHelper, osHelper = requireUtils.tryrequire("utils.system." .. osFilename) function utils.getProcessId()