Make luacheck >= 0.26 happy (#9174)

Re: https://github.com/koreader/koreader-base/pull/1487
reviewable/pr9200/r1
NiLuJe 2 years ago committed by GitHub
parent d644b1a851
commit dcb11c2542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -75,79 +75,79 @@ function ReaderHighlight:init()
self._highlight_buttons = { self._highlight_buttons = {
-- highlight and add_note are for the document itself, -- highlight and add_note are for the document itself,
-- so we put them first. -- so we put them first.
["01_select"] = function(_self) ["01_select"] = function(this)
return { return {
text = _("Select"), text = _("Select"),
enabled = _self.hold_pos ~= nil, enabled = this.hold_pos ~= nil,
callback = function() callback = function()
_self:startSelection() this:startSelection()
_self:onClose() this:onClose()
end, end,
} }
end, end,
["02_highlight"] = function(_self) ["02_highlight"] = function(this)
return { return {
text = _("Highlight"), text = _("Highlight"),
callback = function() callback = function()
_self:saveHighlight() this:saveHighlight()
_self:onClose() this:onClose()
end, end,
enabled = _self.hold_pos ~= nil, enabled = this.hold_pos ~= nil,
} }
end, end,
["03_copy"] = function(_self) ["03_copy"] = function(this)
return { return {
text = C_("Text", "Copy"), text = C_("Text", "Copy"),
enabled = Device:hasClipboard(), enabled = Device:hasClipboard(),
callback = function() callback = function()
Device.input.setClipboardText(cleanupSelectedText(_self.selected_text.text)) Device.input.setClipboardText(cleanupSelectedText(this.selected_text.text))
_self:onClose() this:onClose()
UIManager:show(Notification:new{ UIManager:show(Notification:new{
text = _("Selection copied to clipboard."), text = _("Selection copied to clipboard."),
}) })
end, end,
} }
end, end,
["04_add_note"] = function(_self) ["04_add_note"] = function(this)
return { return {
text = _("Add Note"), text = _("Add Note"),
callback = function() callback = function()
_self:addNote() this:addNote()
_self:onClose() this:onClose()
end, end,
enabled = _self.hold_pos ~= nil, enabled = this.hold_pos ~= nil,
} }
end, end,
-- then information lookup functions, putting on the left those that -- then information lookup functions, putting on the left those that
-- depend on an internet connection. -- depend on an internet connection.
["05_wikipedia"] = function(_self) ["05_wikipedia"] = function(this)
return { return {
text = _("Wikipedia"), text = _("Wikipedia"),
callback = function() callback = function()
UIManager:scheduleIn(0.1, function() UIManager:scheduleIn(0.1, function()
_self:lookupWikipedia() this:lookupWikipedia()
-- We don't call _self:onClose(), we need the highlight -- We don't call this:onClose(), we need the highlight
-- to still be there, as we may Highlight it from the -- to still be there, as we may Highlight it from the
-- dict lookup widget. -- dict lookup widget.
end) end)
end, end,
} }
end, end,
["06_dictionary"] = function(_self) ["06_dictionary"] = function(this)
return { return {
text = _("Dictionary"), text = _("Dictionary"),
callback = function() callback = function()
_self:onHighlightDictLookup() this:onHighlightDictLookup()
-- We don't call _self:onClose(), same reason as above -- We don't call this:onClose(), same reason as above
end, end,
} }
end, end,
["07_translate"] = function(_self, page, index) ["07_translate"] = function(this, page, index)
return { return {
text = _("Translate"), text = _("Translate"),
callback = function() callback = function()
_self:translate(_self.selected_text, page, index) this:translate(this.selected_text, page, index)
-- We don't call _self:onClose(), so one can still see -- We don't call this:onClose(), so one can still see
-- the highlighted text when moving the translated -- the highlighted text when moving the translated
-- text window, and also if NetworkMgr:promptWifiOn() -- text window, and also if NetworkMgr:promptWifiOn()
-- is needed, so the user can just tap again on this -- is needed, so the user can just tap again on this
@ -157,12 +157,12 @@ function ReaderHighlight:init()
end, end,
-- buttons 08-11 are conditional ones, so the number of buttons can be even or odd -- 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 -- let the Search button be the last, occasionally narrow or wide, less confusing
["12_search"] = function(_self) ["12_search"] = function(this)
return { return {
text = _("Search"), text = _("Search"),
callback = function() callback = function()
_self:onHighlightSearch() this:onHighlightSearch()
-- We don't call _self:onClose(), crengine will highlight -- We don't call this:onClose(), crengine will highlight
-- search matches on the current page, and self:clear() -- search matches on the current page, and self:clear()
-- would redraw and remove crengine native highlights -- would redraw and remove crengine native highlights
end, end,
@ -173,13 +173,13 @@ function ReaderHighlight:init()
-- Android devices -- Android devices
if Device:canShareText() then if Device:canShareText() then
local action = _("Share Text") local action = _("Share Text")
self:addToHighlightDialog("08_share_text", function(_self) self:addToHighlightDialog("08_share_text", function(this)
return { return {
text = action, text = action,
callback = function() callback = function()
local text = cleanupSelectedText(_self.selected_text.text) local text = cleanupSelectedText(this.selected_text.text)
-- call self:onClose() before calling the android framework -- call self:onClose() before calling the android framework
_self:onClose() this:onClose()
Device:doShareText(text, action) Device:doShareText(text, action)
end, end,
} }
@ -188,42 +188,42 @@ function ReaderHighlight:init()
-- cre documents only -- cre documents only
if not self.document.info.has_pages then if not self.document.info.has_pages then
self:addToHighlightDialog("09_view_html", function(_self) self:addToHighlightDialog("09_view_html", function(this)
return { return {
text = _("View HTML"), text = _("View HTML"),
callback = function() callback = function()
_self:viewSelectionHTML() this:viewSelectionHTML()
end, end,
} }
end) end)
end end
-- User hyphenation dict -- User hyphenation dict
self:addToHighlightDialog("10_user_dict", function(_self) self:addToHighlightDialog("10_user_dict", function(this)
return { return {
text= _("Hyphenate"), text= _("Hyphenate"),
show_in_highlight_dialog_func = function() show_in_highlight_dialog_func = function()
return _self.ui.userhyph and _self.ui.userhyph:isAvailable() return this.ui.userhyph and this.ui.userhyph:isAvailable()
and not _self.selected_text.text:find("[ ,;-%.\n]") and not this.selected_text.text:find("[ ,;-%.\n]")
end, end,
callback = function() callback = function()
_self.ui.userhyph:modifyUserEntry(_self.selected_text.text) this.ui.userhyph:modifyUserEntry(this.selected_text.text)
_self:onClose() this:onClose()
end, end,
} }
end) end)
-- Links -- Links
self:addToHighlightDialog("11_follow_link", function(_self) self:addToHighlightDialog("11_follow_link", function(this)
return { return {
text = _("Follow Link"), text = _("Follow Link"),
show_in_highlight_dialog_func = function() show_in_highlight_dialog_func = function()
return _self.selected_link ~= nil return this.selected_link ~= nil
end, end,
callback = function() callback = function()
local link = _self.selected_link.link or _self.selected_link local link = this.selected_link.link or this.selected_link
_self.ui.link:onGotoLink(link) this.ui.link:onGotoLink(link)
_self:onClose() this:onClose()
end, end,
} }
end) end)

@ -171,10 +171,10 @@ function ReaderSearch:onShowSearchDialog(text, direction, regex, case_insensitiv
end end
return false return false
end end
local do_search = function(search_func, _text, param) local do_search = function(search_func, search_term, param)
return function() return function()
local no_results = true -- for notification 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 res then
if self.ui.document.info.has_pages then if self.ui.document.info.has_pages then
no_results = false no_results = false

@ -170,7 +170,7 @@ Set frontlight level.
@int new_intensity @int new_intensity
--]] --]]
function NickelConf.frontLightLevel.set(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, return NickelConf._write_kobo_conf(re_FrontLightLevel,
front_light_level_str, front_light_level_str,
new_intensity) new_intensity)

@ -1743,13 +1743,13 @@ function CreDocument:setupCallCache()
end end
end end
-- We override a bit more specifically the one responsible for drawing page -- 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 do_draw = false
local current_tag = _self._callCacheGetCurrentTag() local current_tag = this._callCacheGetCurrentTag()
local current_buffer_tag = _self._callCacheGet("current_buffer_tag") local current_buffer_tag = this._callCacheGet("current_buffer_tag")
if _self.buffer and (_self.buffer.w ~= rect.w or _self.buffer.h ~= rect.h) then if this.buffer and (this.buffer.w ~= rect.w or this.buffer.h ~= rect.h) then
do_draw = true do_draw = true
elseif not _self.buffer then elseif not this.buffer then
do_draw = true do_draw = true
elseif not current_buffer_tag then elseif not current_buffer_tag then
do_draw = true do_draw = true
@ -1759,20 +1759,20 @@ function CreDocument:setupCallCache()
local starttime = now() local starttime = now()
if do_draw then if do_draw then
if do_log then logger.dbg("callCache: ########## drawCurrentView: full draw") end 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) addStatMiss("drawCurrentView", starttime)
_self._callCacheSet("current_buffer_tag", current_tag) this._callCacheSet("current_buffer_tag", current_tag)
else else
if do_log then logger.dbg("callCache: ---------- drawCurrentView: light draw") end 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) addStatHit("drawCurrentView", starttime)
end end
end end
-- Dump statistics on close -- Dump statistics on close
if do_stats then if do_stats then
self.close = function(_self) self.close = function(this)
dumpStats() dumpStats()
CreDocument.close(_self) CreDocument.close(this)
end end
end end
end end

@ -1095,9 +1095,9 @@ end
Get link from position in screen page. Get link from position in screen page.
]]-- ]]--
function KoptInterface:getLinkFromPosition(doc, pageno, pos) function KoptInterface:getLinkFromPosition(doc, pageno, pos)
local function _inside_box(_pos, box) local function _inside_box(coords, box)
if _pos then if coords then
local x, y = _pos.x, _pos.y local x, y = coords.x, coords.y
if box.x <= x and box.y <= y if box.x <= x and box.y <= y
and box.x + box.w >= x and box.x + box.w >= x
and box.y + box.h >= y then and box.y + box.h >= y then

@ -6,7 +6,7 @@ local isUbuntuTouch = os.getenv("UBUNTU_APPLICATION_ISOLATION") ~= nil
local insert = table.insert local insert = table.insert
local indent_prefix = " " 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 if not max_lv then
max_lv = math.huge max_lv = math.huge
end end
@ -28,13 +28,13 @@ local function _serialize(what, outt, indent, max_lv, history, _pairs)
local new_history = { what, unpack(history) } local new_history = { what, unpack(history) }
local didrun = false local didrun = false
insert(outt, "{") insert(outt, "{")
for k, v in _pairs(what) do for k, v in pairs_func(what) do
insert(outt, "\n") insert(outt, "\n")
insert(outt, string.rep(indent_prefix, indent+1)) insert(outt, string.rep(indent_prefix, indent+1))
insert(outt, "[") 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, "] = ") 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, ",") insert(outt, ",")
didrun = true didrun = true
end end
@ -73,8 +73,8 @@ You can optionally specify a maximum recursion depth in `max_lv`.
--]] --]]
local function dump(data, max_lv, ordered) local function dump(data, max_lv, ordered)
local out = {} local out = {}
local _pairs = ordered and require("ffi/util").orderedPairs or pairs local pairs_func = ordered and require("ffi/util").orderedPairs or pairs
_serialize(data, out, 0, max_lv, nil, _pairs) _serialize(data, out, 0, max_lv, nil, pairs_func)
return table.concat(out) return table.concat(out)
end end

@ -103,7 +103,7 @@ local function getPluralFunc(pl_tests, nplurals, plural_default)
local pl_test = pl_tests[i] local pl_test = pl_tests[i]
pl_test = logicalCtoLua(pl_test) 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 pl_test = " elseif "..pl_test
end end
if tonumber(pl_test) ~= nil then if tonumber(pl_test) ~= nil then

@ -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 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 InfoMessage = require("ui/widget/infomessage")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
UIManager:show(InfoMessage:new{ 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."), or _("DPI set to auto. This will take effect after restarting."),
}) })
-- If this is set to nil, reader.lua doesn't call setScreenDPI -- 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 -- Passing a nil properly resets to defaults/auto
Device:setScreenDPI(_dpi) Device:setScreenDPI(dpi_val)
end end
local function spinWidgetSetDPI(touchmenu_instance) local function spinWidgetSetDPI(touchmenu_instance)

@ -184,7 +184,7 @@ function RenderImage:scaleBlitBuffer(bb, width, height, free_orig_bb)
if not Mupdf then Mupdf = require("ffi/mupdf") end if not Mupdf then Mupdf = require("ffi/mupdf") end
scaled_bb = Mupdf.scaleBlitBuffer(bb, width, height) scaled_bb = Mupdf.scaleBlitBuffer(bb, width, height)
end end
if not free_orig_bb == false then if free_orig_bb ~= false then
bb:free() bb:free()
end end
return scaled_bb return scaled_bb

@ -115,7 +115,7 @@ function KOSync:onReaderReady()
self.kosync_custom_server = settings.custom_server self.kosync_custom_server = settings.custom_server
self.kosync_username = settings.username self.kosync_username = settings.username
self.kosync_userkey = settings.userkey 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_pages_before_update = settings.pages_before_update
self.kosync_whisper_forward = settings.whisper_forward or SYNC_STRATEGY.DEFAULT_FORWARD self.kosync_whisper_forward = settings.whisper_forward or SYNC_STRATEGY.DEFAULT_FORWARD
self.kosync_whisper_backward = settings.whisper_backward or SYNC_STRATEGY.DEFAULT_BACKWARD self.kosync_whisper_backward = settings.whisper_backward or SYNC_STRATEGY.DEFAULT_BACKWARD

@ -205,8 +205,8 @@ describe("Readerrolling module", function()
it("should emit PageUpdate event after book is rendered", function() it("should emit PageUpdate event after book is rendered", function()
local ReaderView = require("apps/reader/modules/readerview") local ReaderView = require("apps/reader/modules/readerview")
local saved_handler = ReaderView.onPageUpdate local saved_handler = ReaderView.onPageUpdate
ReaderView.onPageUpdate = function(_self) ReaderView.onPageUpdate = function(this)
assert.are.same(6, _self.ui.document:getPageCount()) assert.are.same(6, this.ui.document:getPageCount())
end end
local test_book = "spec/front/unit/data/sample.txt" local test_book = "spec/front/unit/data/sample.txt"
require("docsettings"):open(test_book):purge() require("docsettings"):open(test_book):purge()

Loading…
Cancel
Save