From b3ae1caf8bcdb5fd4280d727f428f9a61eb14986 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Fri, 22 May 2020 20:59:06 +0200 Subject: [PATCH] [lua] foreachi replaced by ipairs. Refs #46 --- contrib/lua/bm.lua | 8 +++---- contrib/lua/hooks.lua.in | 45 ++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/contrib/lua/bm.lua b/contrib/lua/bm.lua index 362c174d..76568f96 100644 --- a/contrib/lua/bm.lua +++ b/contrib/lua/bm.lua @@ -69,10 +69,10 @@ end function bm_sort_bookmarks () if not bm_auto_sort_bookmarks then return end table.sort (bm_bookmarks, function (a, b) return a.category < b.category end) - foreachi (bm_bookmarks, - function (i, v) - table.sort (v, function (a, b) return a.name < b. name end) - end) + for i,v in ipairs(bm_bookmarks) + do + table.sort (v, function (a, b) return a.name < b. name end) + end end diff --git a/contrib/lua/hooks.lua.in b/contrib/lua/hooks.lua.in index c0283d40..dfa4cd3a 100644 --- a/contrib/lua/hooks.lua.in +++ b/contrib/lua/hooks.lua.in @@ -81,48 +81,47 @@ pre_format_html_hooks = {n=0} function pre_format_html_hook (url, html) local changed = nil - table.foreachi(pre_format_html_hooks, - function (i, fn) - local new,stop = fn(url,html) + for i,fn in ipairs(pre_format_html_hooks) + do + local new,stop = fn(url,html) - if new then html=new changed=1 end - return stop - end) + if new then html=new changed=1 end + end - return changed and html + return changed and html end goto_url_hooks = {n=0} function goto_url_hook (url, current_url) - table.foreachi(goto_url_hooks, - function (i, fn) - local new,stop = fn(url, current_url) + for i,fn in ipairs(goto_url_hooks) + do + local new,stop = fn(url, current_url) - url = new + url = new + end - return stop - end) - - return url + return url end follow_url_hooks = {n=0} function follow_url_hook (url) - table.foreachi(follow_url_hooks, - function (i, fn) - local new,stop = fn(url) + for i,fn in ipairs(follow_url_hooks) + do + local new,stop = fn(url) - url = new + url = new - return stop - end) + end - return url + return url end quit_hooks = {n=0} function quit_hook (url, html) - table.foreachi(quit_hooks, function (i, fn) return fn() end) + for i, fn in ipairs(quit_hooks) + do + fn() + end end ----------------------------------------------------------------------