diff --git a/Makefile b/Makefile index 27b15162a..68f7794d1 100644 --- a/Makefile +++ b/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'"; \ diff --git a/datastorage.lua b/datastorage.lua index 8d49e6617..e57f0ff99 100644 --- a/datastorage.lua +++ b/datastorage.lua @@ -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 diff --git a/kodev b/kodev index 9f8ccb5a3..6ce99864e 100755 --- a/kodev +++ b/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) diff --git a/reader.lua b/reader.lua index d8d2379f0..769e76b42 100755 --- a/reader.lua +++ b/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 - --- 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 +require("setupkoenv") -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 diff --git a/setupkoenv.lua b/setupkoenv.lua new file mode 100644 index 000000000..4b4513f15 --- /dev/null +++ b/setupkoenv.lua @@ -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