diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 4f200ebab..d967d6bac 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -75,79 +75,79 @@ function ReaderHighlight:init() self._highlight_buttons = { -- highlight and add_note are for the document itself, -- so we put them first. - ["01_select"] = function(_self) + ["01_select"] = function(this) return { text = _("Select"), - enabled = _self.hold_pos ~= nil, + enabled = this.hold_pos ~= nil, callback = function() - _self:startSelection() - _self:onClose() + this:startSelection() + this:onClose() end, } end, - ["02_highlight"] = function(_self) + ["02_highlight"] = function(this) return { text = _("Highlight"), callback = function() - _self:saveHighlight() - _self:onClose() + this:saveHighlight() + this:onClose() end, - enabled = _self.hold_pos ~= nil, + enabled = this.hold_pos ~= nil, } end, - ["03_copy"] = function(_self) + ["03_copy"] = function(this) return { text = C_("Text", "Copy"), enabled = Device:hasClipboard(), callback = function() - Device.input.setClipboardText(cleanupSelectedText(_self.selected_text.text)) - _self:onClose() + Device.input.setClipboardText(cleanupSelectedText(this.selected_text.text)) + this:onClose() UIManager:show(Notification:new{ text = _("Selection copied to clipboard."), }) end, } end, - ["04_add_note"] = function(_self) + ["04_add_note"] = function(this) return { text = _("Add Note"), callback = function() - _self:addNote() - _self:onClose() + this:addNote() + this:onClose() end, - enabled = _self.hold_pos ~= nil, + enabled = this.hold_pos ~= nil, } end, -- then information lookup functions, putting on the left those that -- depend on an internet connection. - ["05_wikipedia"] = function(_self) + ["05_wikipedia"] = function(this) return { text = _("Wikipedia"), callback = function() UIManager:scheduleIn(0.1, function() - _self:lookupWikipedia() - -- We don't call _self:onClose(), we need the highlight + this:lookupWikipedia() + -- We don't call this:onClose(), we need the highlight -- to still be there, as we may Highlight it from the -- dict lookup widget. end) end, } end, - ["06_dictionary"] = function(_self) + ["06_dictionary"] = function(this) return { text = _("Dictionary"), callback = function() - _self:onHighlightDictLookup() - -- We don't call _self:onClose(), same reason as above + this:onHighlightDictLookup() + -- We don't call this:onClose(), same reason as above end, } end, - ["07_translate"] = function(_self, page, index) + ["07_translate"] = function(this, page, index) return { text = _("Translate"), callback = function() - _self:translate(_self.selected_text, page, index) - -- We don't call _self:onClose(), so one can still see + this:translate(this.selected_text, page, index) + -- We don't call this:onClose(), so one can still see -- the highlighted text when moving the translated -- text window, and also if NetworkMgr:promptWifiOn() -- is needed, so the user can just tap again on this @@ -157,12 +157,12 @@ function ReaderHighlight:init() end, -- buttons 08-11 are conditional ones, so the number of buttons can be even or odd -- let the Search button be the last, occasionally narrow or wide, less confusing - ["12_search"] = function(_self) + ["12_search"] = function(this) return { text = _("Search"), callback = function() - _self:onHighlightSearch() - -- We don't call _self:onClose(), crengine will highlight + this:onHighlightSearch() + -- We don't call this:onClose(), crengine will highlight -- search matches on the current page, and self:clear() -- would redraw and remove crengine native highlights end, @@ -173,13 +173,13 @@ function ReaderHighlight:init() -- Android devices if Device:canShareText() then local action = _("Share Text") - self:addToHighlightDialog("08_share_text", function(_self) + self:addToHighlightDialog("08_share_text", function(this) return { text = action, callback = function() - local text = cleanupSelectedText(_self.selected_text.text) + local text = cleanupSelectedText(this.selected_text.text) -- call self:onClose() before calling the android framework - _self:onClose() + this:onClose() Device:doShareText(text, action) end, } @@ -188,42 +188,42 @@ function ReaderHighlight:init() -- cre documents only if not self.document.info.has_pages then - self:addToHighlightDialog("09_view_html", function(_self) + self:addToHighlightDialog("09_view_html", function(this) return { text = _("View HTML"), callback = function() - _self:viewSelectionHTML() + this:viewSelectionHTML() end, } end) end -- User hyphenation dict - self:addToHighlightDialog("10_user_dict", function(_self) + self:addToHighlightDialog("10_user_dict", function(this) return { text= _("Hyphenate"), show_in_highlight_dialog_func = function() - return _self.ui.userhyph and _self.ui.userhyph:isAvailable() - and not _self.selected_text.text:find("[ ,;-%.\n]") + return this.ui.userhyph and this.ui.userhyph:isAvailable() + and not this.selected_text.text:find("[ ,;-%.\n]") end, callback = function() - _self.ui.userhyph:modifyUserEntry(_self.selected_text.text) - _self:onClose() + this.ui.userhyph:modifyUserEntry(this.selected_text.text) + this:onClose() end, } end) -- Links - self:addToHighlightDialog("11_follow_link", function(_self) + self:addToHighlightDialog("11_follow_link", function(this) return { text = _("Follow Link"), show_in_highlight_dialog_func = function() - return _self.selected_link ~= nil + return this.selected_link ~= nil end, callback = function() - local link = _self.selected_link.link or _self.selected_link - _self.ui.link:onGotoLink(link) - _self:onClose() + local link = this.selected_link.link or this.selected_link + this.ui.link:onGotoLink(link) + this:onClose() end, } end) diff --git a/frontend/apps/reader/modules/readersearch.lua b/frontend/apps/reader/modules/readersearch.lua index 042561365..a40038807 100644 --- a/frontend/apps/reader/modules/readersearch.lua +++ b/frontend/apps/reader/modules/readersearch.lua @@ -171,10 +171,10 @@ function ReaderSearch:onShowSearchDialog(text, direction, regex, case_insensitiv end return false end - local do_search = function(search_func, _text, param) + local do_search = function(search_func, search_term, param) return function() local no_results = true -- for notification - local res = search_func(self, _text, param, regex, case_insensitive) + local res = search_func(self, search_term, param, regex, case_insensitive) if res then if self.ui.document.info.has_pages then no_results = false diff --git a/frontend/device/kobo/nickel_conf.lua b/frontend/device/kobo/nickel_conf.lua index 0f76b3ff3..fbc7cc339 100644 --- a/frontend/device/kobo/nickel_conf.lua +++ b/frontend/device/kobo/nickel_conf.lua @@ -170,7 +170,7 @@ Set frontlight level. @int new_intensity --]] function NickelConf.frontLightLevel.set(new_intensity) - if type(new_intensity) ~= "number" or (not (new_intensity >= 0) and (not new_intensity <= 100)) then return end + if type(new_intensity) ~= "number" or (new_intensity < 0 or new_intensity > 100) then return end return NickelConf._write_kobo_conf(re_FrontLightLevel, front_light_level_str, new_intensity) diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index 5d864410a..ad264a674 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -1743,13 +1743,13 @@ function CreDocument:setupCallCache() end end -- We override a bit more specifically the one responsible for drawing page - self.drawCurrentView = function(_self, target, x, y, rect, pos) + self.drawCurrentView = function(this, target, x, y, rect, pos) local do_draw = false - local current_tag = _self._callCacheGetCurrentTag() - local current_buffer_tag = _self._callCacheGet("current_buffer_tag") - if _self.buffer and (_self.buffer.w ~= rect.w or _self.buffer.h ~= rect.h) then + local current_tag = this._callCacheGetCurrentTag() + local current_buffer_tag = this._callCacheGet("current_buffer_tag") + if this.buffer and (this.buffer.w ~= rect.w or this.buffer.h ~= rect.h) then do_draw = true - elseif not _self.buffer then + elseif not this.buffer then do_draw = true elseif not current_buffer_tag then do_draw = true @@ -1759,20 +1759,20 @@ function CreDocument:setupCallCache() local starttime = now() if do_draw then if do_log then logger.dbg("callCache: ########## drawCurrentView: full draw") end - CreDocument.drawCurrentView(_self, target, x, y, rect, pos) + CreDocument.drawCurrentView(this, target, x, y, rect, pos) addStatMiss("drawCurrentView", starttime) - _self._callCacheSet("current_buffer_tag", current_tag) + this._callCacheSet("current_buffer_tag", current_tag) else if do_log then logger.dbg("callCache: ---------- drawCurrentView: light draw") end - target:blitFrom(_self.buffer, x, y, 0, 0, rect.w, rect.h) + target:blitFrom(this.buffer, x, y, 0, 0, rect.w, rect.h) addStatHit("drawCurrentView", starttime) end end -- Dump statistics on close if do_stats then - self.close = function(_self) + self.close = function(this) dumpStats() - CreDocument.close(_self) + CreDocument.close(this) end end end diff --git a/frontend/document/koptinterface.lua b/frontend/document/koptinterface.lua index c43457fd0..0a40fbcd4 100644 --- a/frontend/document/koptinterface.lua +++ b/frontend/document/koptinterface.lua @@ -1095,9 +1095,9 @@ end Get link from position in screen page. ]]-- function KoptInterface:getLinkFromPosition(doc, pageno, pos) - local function _inside_box(_pos, box) - if _pos then - local x, y = _pos.x, _pos.y + local function _inside_box(coords, box) + if coords then + local x, y = coords.x, coords.y if box.x <= x and box.y <= y and box.x + box.w >= x and box.y + box.h >= y then diff --git a/frontend/dump.lua b/frontend/dump.lua index aa74e8704..06528bb47 100644 --- a/frontend/dump.lua +++ b/frontend/dump.lua @@ -6,7 +6,7 @@ local isUbuntuTouch = os.getenv("UBUNTU_APPLICATION_ISOLATION") ~= nil local insert = table.insert local indent_prefix = " " -local function _serialize(what, outt, indent, max_lv, history, _pairs) +local function _serialize(what, outt, indent, max_lv, history, pairs_func) if not max_lv then max_lv = math.huge end @@ -28,13 +28,13 @@ local function _serialize(what, outt, indent, max_lv, history, _pairs) local new_history = { what, unpack(history) } local didrun = false insert(outt, "{") - for k, v in _pairs(what) do + for k, v in pairs_func(what) do insert(outt, "\n") insert(outt, string.rep(indent_prefix, indent+1)) insert(outt, "[") - _serialize(k, outt, indent+1, max_lv, new_history, _pairs) + _serialize(k, outt, indent+1, max_lv, new_history, pairs_func) insert(outt, "] = ") - _serialize(v, outt, indent+1, max_lv, new_history, _pairs) + _serialize(v, outt, indent+1, max_lv, new_history, pairs_func) insert(outt, ",") didrun = true end @@ -73,8 +73,8 @@ You can optionally specify a maximum recursion depth in `max_lv`. --]] local function dump(data, max_lv, ordered) local out = {} - local _pairs = ordered and require("ffi/util").orderedPairs or pairs - _serialize(data, out, 0, max_lv, nil, _pairs) + local pairs_func = ordered and require("ffi/util").orderedPairs or pairs + _serialize(data, out, 0, max_lv, nil, pairs_func) return table.concat(out) end diff --git a/frontend/gettext.lua b/frontend/gettext.lua index 4dc72dac3..d9b1f3fee 100644 --- a/frontend/gettext.lua +++ b/frontend/gettext.lua @@ -103,7 +103,7 @@ local function getPluralFunc(pl_tests, nplurals, plural_default) local pl_test = pl_tests[i] pl_test = logicalCtoLua(pl_test) - if i > 1 and not (tonumber(pl_test) ~= nil) then + if i > 1 and tonumber(pl_test) == nil then pl_test = " elseif "..pl_test end if tonumber(pl_test) ~= nil then diff --git a/frontend/ui/elements/screen_dpi_menu_table.lua b/frontend/ui/elements/screen_dpi_menu_table.lua index 10903f4ca..a2b0e6541 100644 --- a/frontend/ui/elements/screen_dpi_menu_table.lua +++ b/frontend/ui/elements/screen_dpi_menu_table.lua @@ -9,17 +9,17 @@ local function dpi() return Screen:getDPI() end local function custom() return G_reader_settings:readSetting("custom_screen_dpi") end -local function setDPI(_dpi) +local function setDPI(dpi_val) local InfoMessage = require("ui/widget/infomessage") local UIManager = require("ui/uimanager") UIManager:show(InfoMessage:new{ - text = _dpi and T(_("DPI set to %1. This will take effect after restarting."), _dpi) + text = dpi_val and T(_("DPI set to %1. This will take effect after restarting."), dpi_val) or _("DPI set to auto. This will take effect after restarting."), }) -- If this is set to nil, reader.lua doesn't call setScreenDPI - G_reader_settings:saveSetting("screen_dpi", _dpi) + G_reader_settings:saveSetting("screen_dpi", dpi_val) -- Passing a nil properly resets to defaults/auto - Device:setScreenDPI(_dpi) + Device:setScreenDPI(dpi_val) end local function spinWidgetSetDPI(touchmenu_instance) diff --git a/frontend/ui/renderimage.lua b/frontend/ui/renderimage.lua index 0821aedc8..db09d0434 100644 --- a/frontend/ui/renderimage.lua +++ b/frontend/ui/renderimage.lua @@ -184,7 +184,7 @@ function RenderImage:scaleBlitBuffer(bb, width, height, free_orig_bb) if not Mupdf then Mupdf = require("ffi/mupdf") end scaled_bb = Mupdf.scaleBlitBuffer(bb, width, height) end - if not free_orig_bb == false then + if free_orig_bb ~= false then bb:free() end return scaled_bb diff --git a/plugins/kosync.koplugin/main.lua b/plugins/kosync.koplugin/main.lua index 8903131c0..48c650f34 100644 --- a/plugins/kosync.koplugin/main.lua +++ b/plugins/kosync.koplugin/main.lua @@ -115,7 +115,7 @@ function KOSync:onReaderReady() self.kosync_custom_server = settings.custom_server self.kosync_username = settings.username self.kosync_userkey = settings.userkey - self.kosync_auto_sync = not (settings.auto_sync == false) + self.kosync_auto_sync = settings.auto_sync ~= false self.kosync_pages_before_update = settings.pages_before_update self.kosync_whisper_forward = settings.whisper_forward or SYNC_STRATEGY.DEFAULT_FORWARD self.kosync_whisper_backward = settings.whisper_backward or SYNC_STRATEGY.DEFAULT_BACKWARD diff --git a/spec/unit/readerrolling_spec.lua b/spec/unit/readerrolling_spec.lua index 964351fbe..8cfe62aa8 100644 --- a/spec/unit/readerrolling_spec.lua +++ b/spec/unit/readerrolling_spec.lua @@ -205,8 +205,8 @@ describe("Readerrolling module", function() it("should emit PageUpdate event after book is rendered", function() local ReaderView = require("apps/reader/modules/readerview") local saved_handler = ReaderView.onPageUpdate - ReaderView.onPageUpdate = function(_self) - assert.are.same(6, _self.ui.document:getPageCount()) + ReaderView.onPageUpdate = function(this) + assert.are.same(6, this.ui.document:getPageCount()) end local test_book = "spec/front/unit/data/sample.txt" require("docsettings"):open(test_book):purge()