From e6d0dea42b28a4814546bcf699ce277c365ebfc1 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Tue, 27 Nov 2018 16:29:43 +0100 Subject: test: Lua 5.2/5.3 compat #9280 Make the code run both on Lua 5.1 (which is the default for Neovim, and is what LuaJIT provides) and Lua 5.2+. --- runtime/lua/man.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'runtime/lua') diff --git a/runtime/lua/man.lua b/runtime/lua/man.lua index b0fbe9cc35..0c67e45dc4 100644 --- a/runtime/lua/man.lua +++ b/runtime/lua/man.lua @@ -1,4 +1,5 @@ local buf_hls = {} +local unpack = table.unpack or unpack -- luacheck: ignore local function highlight_line(line, linenr) local chars = {} -- cgit From 221f6fffad12beaa928ccedae336d64b7b1c1208 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 29 Nov 2018 22:51:20 +0100 Subject: runtime/lua/vim/compat.lua ref #9280 Introduce the `vim.compat` module, to help environments with system Lua 5.2+ run the build/tests. Include the module implicitly in all tests. ref #8677 legacy `vim` module: beep buffer command dict eval firstline lastline line list open type window --- runtime/lua/man.lua | 3 ++- runtime/lua/vim/compat.lua | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 runtime/lua/vim/compat.lua (limited to 'runtime/lua') diff --git a/runtime/lua/man.lua b/runtime/lua/man.lua index 0c67e45dc4..e9f60138f4 100644 --- a/runtime/lua/man.lua +++ b/runtime/lua/man.lua @@ -1,5 +1,6 @@ +require('vim.compat') + local buf_hls = {} -local unpack = table.unpack or unpack -- luacheck: ignore local function highlight_line(line, linenr) local chars = {} diff --git a/runtime/lua/vim/compat.lua b/runtime/lua/vim/compat.lua new file mode 100644 index 0000000000..168979bb95 --- /dev/null +++ b/runtime/lua/vim/compat.lua @@ -0,0 +1,12 @@ +-- Lua 5.1 forward-compatibility layer. +-- For background see https://github.com/neovim/neovim/pull/9280 +-- +-- Reference the lua-compat-5.2 project for hints: +-- https://github.com/keplerproject/lua-compat-5.2/blob/c164c8f339b95451b572d6b4b4d11e944dc7169d/compat52/mstrict.lua +-- https://github.com/keplerproject/lua-compat-5.2/blob/c164c8f339b95451b572d6b4b4d11e944dc7169d/tests/test.lua + +local lua_version = _VERSION:sub(-3) + +if lua_version >= "5.2" then + unpack = table.unpack -- luacheck: ignore 121 143 +end -- cgit From 127b8569e63d57321fc4cd77b7e55781f1447365 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 30 Nov 2018 21:30:05 +0100 Subject: lint --- runtime/lua/man.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'runtime/lua') diff --git a/runtime/lua/man.lua b/runtime/lua/man.lua index e9f60138f4..1da8ed85fc 100644 --- a/runtime/lua/man.lua +++ b/runtime/lua/man.lua @@ -12,9 +12,9 @@ local function highlight_line(line, linenr) local attr = NONE local byte = 0 -- byte offset - local function end_attr_hl(attr) + local function end_attr_hl(attr_) for i, hl in ipairs(hls) do - if hl.attr == attr and hl.final == -1 then + if hl.attr == attr_ and hl.final == -1 then hl.final = byte hls[i] = hl end @@ -108,7 +108,7 @@ local function highlight_line(line, linenr) -- the range 0x20 - 0x3f, then 'm'. (See ECMA-48, sections 5.4 & 8.3.117) local sgr = prev_char:match("^%[([\032-\063]*)m$") if sgr then - local match = '' + local match while sgr and #sgr > 0 do -- Match against SGR parameters, which may be separated by ';' match, sgr = sgr:match("^(%d*);?(.*)") -- cgit