mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
refactor: move bootstrap code into setupkoenv.lua
add ffi.load patch add kodev prompt command
This commit is contained in:
6
Makefile
6
Makefile
@@ -38,8 +38,8 @@ UBUNTUTOUCH_SDL_DIR:=$(UBUNTUTOUCH_DIR)/ubuntu-touch-sdl
|
||||
WIN32_DIR=$(PLATFORM_DIR)/win32
|
||||
|
||||
# files to link from main directory
|
||||
INSTALL_FILES=reader.lua frontend resources defaults.lua datastorage.lua l10n tools \
|
||||
README.md COPYING
|
||||
INSTALL_FILES=reader.lua setupkoenv.lua frontend resources defaults.lua datastorage.lua \
|
||||
l10n tools README.md COPYING
|
||||
|
||||
# for gettext
|
||||
DOMAIN=koreader
|
||||
@@ -359,7 +359,7 @@ po:
|
||||
|
||||
static-check:
|
||||
@if which luacheck > /dev/null; then \
|
||||
luacheck -q frontend plugins; \
|
||||
luacheck -q {reader,setupkoenv,datastorage}.lua frontend plugins; \
|
||||
else \
|
||||
echo "[!] luacheck not found. "\
|
||||
"you can install it with 'luarocks install luacheck'"; \
|
||||
|
||||
@@ -34,13 +34,12 @@ function DataStorage:getSettingsDir()
|
||||
end
|
||||
|
||||
local function initDataDir()
|
||||
local data_dir = DataStorage:getDataDir()
|
||||
local sub_data_dirs = {
|
||||
"cache", "clipboard", "data", "history",
|
||||
"ota", "screenshots", "settings",
|
||||
}
|
||||
for _, dir in ipairs(sub_data_dirs) do
|
||||
local sub_data_dir = data_dir .. "/" .. dir
|
||||
local sub_data_dir = DataStorage:getDataDir() .. "/" .. dir
|
||||
if lfs.attributes(sub_data_dir, "mode") ~= "directory" then
|
||||
lfs.mkdir(sub_data_dir)
|
||||
end
|
||||
|
||||
6
kodev
6
kodev
@@ -379,6 +379,12 @@ case $1 in
|
||||
shift 1; kodev-run "$@" ;;
|
||||
test)
|
||||
shift 1; kodev-test "$@" ;;
|
||||
prompt)
|
||||
kodev-build
|
||||
pushd "${EMU_DIR}"
|
||||
./luajit -i setupkoenv.lua
|
||||
popd
|
||||
;;
|
||||
log)
|
||||
shift 1; kodev-log "$@" ;;
|
||||
--help | -h)
|
||||
|
||||
24
reader.lua
24
reader.lua
@@ -14,37 +14,19 @@ io.stdout:flush()
|
||||
|
||||
|
||||
-- load default settings
|
||||
require "defaults"
|
||||
require("defaults")
|
||||
local DataStorage = require("datastorage")
|
||||
pcall(dofile, DataStorage:getDataDir() .. "/defaults.persistent.lua")
|
||||
|
||||
-- set search path for 'require()'
|
||||
package.path =
|
||||
"common/?.lua;rocks/share/lua/5.1/?.lua;frontend/?.lua;" ..
|
||||
package.path
|
||||
package.cpath =
|
||||
"common/?.so;common/?.dll;/usr/lib/lua/?.so;rocks/lib/lua/5.1/?.so;" ..
|
||||
package.cpath
|
||||
require("setupkoenv")
|
||||
|
||||
-- set search path for 'ffi.load()'
|
||||
local ffi = require("ffi")
|
||||
local util = require("ffi/util")
|
||||
ffi.cdef[[
|
||||
char *getenv(const char *name);
|
||||
int putenv(const char *envvar);
|
||||
int _putenv(const char *envvar);
|
||||
]]
|
||||
if ffi.os == "Windows" then
|
||||
ffi.C._putenv("PATH=libs;common;")
|
||||
end
|
||||
|
||||
local _ = require("gettext")
|
||||
-- read settings and check for language override
|
||||
-- has to be done before requiring other files because
|
||||
-- they might call gettext on load
|
||||
G_reader_settings = require("luasettings"):open(
|
||||
DataStorage:getDataDir().."/settings.reader.lua")
|
||||
local lang_locale = G_reader_settings:readSetting("language")
|
||||
local _ = require("gettext")
|
||||
if lang_locale then
|
||||
_.changeLang(lang_locale)
|
||||
end
|
||||
|
||||
31
setupkoenv.lua
Normal file
31
setupkoenv.lua
Normal file
@@ -0,0 +1,31 @@
|
||||
-- set search path for 'require()'
|
||||
package.path =
|
||||
"common/?.lua;rocks/share/lua/5.1/?.lua;frontend/?.lua;" ..
|
||||
package.path
|
||||
package.cpath =
|
||||
"common/?.so;common/?.dll;/usr/lib/lua/?.so;rocks/lib/lua/5.1/?.so;" ..
|
||||
package.cpath
|
||||
|
||||
-- set search path for 'ffi.load()'
|
||||
local ffi = require("ffi")
|
||||
ffi.cdef[[
|
||||
char *getenv(const char *name);
|
||||
int putenv(const char *envvar);
|
||||
int _putenv(const char *envvar);
|
||||
]]
|
||||
if ffi.os == "Windows" then
|
||||
ffi.C._putenv("PATH=libs;common;")
|
||||
end
|
||||
local ffi_load = ffi.load
|
||||
-- patch ffi.load for thirdparty luajit libraries
|
||||
ffi.load = function(lib)
|
||||
local loaded, re = pcall(ffi_load, lib)
|
||||
if loaded then return re end
|
||||
|
||||
local lib_path = package.searchpath(lib, "./lib?.so;./libs/lib?.so")
|
||||
if not lib_path then
|
||||
error('Not able to load dynamic library: ' .. lib)
|
||||
else
|
||||
return ffi_load(lib_path)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user