2021-05-18 03:46:05 +00:00
|
|
|
-- Check if we're running a busted version recent enough that we don't need to deal with the LuaJIT hacks...
|
|
|
|
-- That currently means > 2.0.0 (i.e., scm-2, which isn't on LuaRocks...).
|
|
|
|
local busted_ok = false
|
|
|
|
for name, _ in pairs(package.loaded) do
|
|
|
|
if name == "busted.luajit" then
|
|
|
|
busted_ok = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Don't try to overwrite metatables so we can use --auto-insulate-tests
|
|
|
|
-- Shamelessly copied from https://github.com/Olivine-Labs/busted/commit/2dfff99bda01fd3da56fd23415aba5a2a4cc0ffd
|
|
|
|
if not busted_ok then
|
|
|
|
local ffi = require "ffi"
|
|
|
|
|
|
|
|
local original_metatype = ffi.metatype
|
|
|
|
local original_store = {}
|
|
|
|
ffi.metatype = function (primary, ...)
|
|
|
|
if original_store[primary] then
|
|
|
|
return original_store[primary]
|
|
|
|
end
|
|
|
|
local success, result, err = pcall(original_metatype, primary, ...)
|
|
|
|
if not success then
|
|
|
|
-- hard error was thrown
|
|
|
|
error(result, 2)
|
|
|
|
end
|
|
|
|
if not result then
|
|
|
|
-- soft error was returned
|
|
|
|
return result, err
|
|
|
|
end
|
|
|
|
-- it worked, store and return
|
|
|
|
original_store[primary] = result
|
|
|
|
return result
|
|
|
|
end
|
2019-04-25 21:33:47 +00:00
|
|
|
end
|
|
|
|
|
2015-03-21 09:02:25 +00:00
|
|
|
package.path = "?.lua;common/?.lua;rocks/share/lua/5.1/?.lua;frontend/?.lua;" .. package.path
|
|
|
|
package.cpath = "?.so;common/?.so;/usr/lib/lua/?.so;rocks/lib/lua/5.1/?.so;" .. package.cpath
|
2014-10-07 05:06:06 +00:00
|
|
|
|
2017-01-23 14:54:14 +00:00
|
|
|
-- turn off debug by default and set log level to warning
|
|
|
|
require("dbg"):turnOff()
|
|
|
|
local logger = require("logger")
|
|
|
|
logger:setLevel(logger.levels.warn)
|
|
|
|
|
2022-09-27 23:10:50 +00:00
|
|
|
-- global defaults
|
2016-03-12 21:59:49 +00:00
|
|
|
local DataStorage = require("datastorage")
|
2022-09-27 23:10:50 +00:00
|
|
|
os.remove(DataStorage:getDataDir() .. "/defaults.tests.lua")
|
|
|
|
os.remove(DataStorage:getDataDir() .. "/defaults.tests.lua.old")
|
|
|
|
G_defaults = require("luadefaults"):open(DataStorage:getDataDir() .. "/defaults.tests.lua")
|
|
|
|
|
|
|
|
-- global reader settings
|
2016-03-12 21:59:49 +00:00
|
|
|
os.remove(DataStorage:getDataDir().."/settings.reader.lua")
|
2016-06-26 00:53:08 +00:00
|
|
|
G_reader_settings = require("luasettings"):open(".reader")
|
2014-10-07 05:06:06 +00:00
|
|
|
|
|
|
|
-- global einkfb for Screen (do not show SDL window)
|
2017-08-08 20:35:40 +00:00
|
|
|
einkfb = require("ffi/framebuffer") --luacheck: ignore
|
|
|
|
einkfb.dummy = true --luacheck: ignore
|
2014-10-07 05:06:06 +00:00
|
|
|
|
2019-02-11 01:07:50 +00:00
|
|
|
local Device = require("device")
|
|
|
|
|
2014-10-07 05:06:06 +00:00
|
|
|
-- init output device
|
2019-02-11 01:07:50 +00:00
|
|
|
local Screen = Device.screen
|
2014-10-07 05:06:06 +00:00
|
|
|
Screen:init()
|
|
|
|
|
2019-04-23 07:21:23 +00:00
|
|
|
local CanvasContext = require("document/canvascontext")
|
|
|
|
CanvasContext:init(Device)
|
|
|
|
|
2014-10-07 05:06:06 +00:00
|
|
|
-- init input device (do not show SDL window)
|
2019-02-11 01:07:50 +00:00
|
|
|
local Input = Device.input
|
2014-10-07 05:06:06 +00:00
|
|
|
Input.dummy = true
|
|
|
|
|
2017-06-14 17:32:16 +00:00
|
|
|
package.unload = function(module)
|
|
|
|
if type(module) ~= "string" then return false end
|
|
|
|
package.loaded[module] = nil
|
|
|
|
_G[module] = nil
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
package.replace = function(name, module)
|
|
|
|
if type(name) ~= "string" then return false end
|
|
|
|
assert(package.unload(name))
|
|
|
|
package.loaded[name] = module
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
package.reload = function(name)
|
|
|
|
if type(name) ~= "string" then return false end
|
|
|
|
assert(package.unload(name))
|
|
|
|
return require(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
package.unloadAll = function()
|
|
|
|
local candidates = {
|
|
|
|
"spec/",
|
|
|
|
"frontend/",
|
|
|
|
"plugins/",
|
|
|
|
"datastorage.lua",
|
|
|
|
"defaults.lua",
|
|
|
|
}
|
|
|
|
local pending = {}
|
|
|
|
for name, _ in pairs(package.loaded) do
|
|
|
|
local path = package.searchpath(name, package.path)
|
|
|
|
if path ~= nil then
|
|
|
|
for _, candidate in ipairs(candidates) do
|
|
|
|
if path:find(candidate) == 1 then
|
|
|
|
table.insert(pending, name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for _, name in ipairs(pending) do
|
|
|
|
if name ~= "commonrequire" then
|
|
|
|
assert(package.unload(name))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return #pending
|
|
|
|
end
|
2017-07-28 14:48:19 +00:00
|
|
|
|
|
|
|
local background_runner
|
|
|
|
requireBackgroundRunner = function()
|
|
|
|
require("pluginshare").stopBackgroundRunner = nil
|
|
|
|
if background_runner == nil then
|
|
|
|
local package_path = package.path
|
|
|
|
package.path = "plugins/backgroundrunner.koplugin/?.lua;" .. package.path
|
|
|
|
background_runner = dofile("plugins/backgroundrunner.koplugin/main.lua")
|
|
|
|
package.path = package_path
|
|
|
|
end
|
|
|
|
return background_runner
|
|
|
|
end
|
|
|
|
|
|
|
|
stopBackgroundRunner = function()
|
|
|
|
background_runner = nil
|
|
|
|
require("pluginshare").stopBackgroundRunner = true
|
|
|
|
end
|
2020-08-31 14:48:29 +00:00
|
|
|
|
|
|
|
notifyBackgroundJobsUpdated = function()
|
|
|
|
if background_runner then
|
|
|
|
background_runner:onBackgroundJobsUpdated()
|
|
|
|
end
|
|
|
|
end
|