Skip to content

Commit b39a789

Browse files
authored
fix: add compatibility for Lua 5.1 (#456)
Some architectures don't support LuaJIT. Remove the goto's from the code to be compatible with Neovim built without LuaJIT. Signed-off-by: Julian Ruess <[email protected]>
1 parent fcca212 commit b39a789

File tree

2 files changed

+109
-107
lines changed

2 files changed

+109
-107
lines changed

lua/oil/mutator/parser.lua

+99-95
Original file line numberDiff line numberDiff line change
@@ -192,115 +192,119 @@ M.parse = function(bufnr)
192192
seen_names[name] = true
193193
end
194194
end
195-
for i, line in ipairs(lines) do
196-
if line:match("^/%d+") then
197-
-- Parse the line for an existing entry
198-
local result, err = M.parse_line(adapter, line, column_defs)
199-
if not result or err then
200-
table.insert(errors, {
201-
message = err,
202-
lnum = i - 1,
203-
end_lnum = i,
204-
col = 0,
205-
})
206-
goto continue
207-
elseif result.data.id == 0 then
208-
-- Ignore entries with ID 0 (typically the "../" entry)
209-
goto continue
210-
end
211-
local parsed_entry = result.data
212-
local entry = result.entry
213195

214-
local err_message
215-
if not parsed_entry.name then
216-
err_message = "No filename found"
217-
elseif not entry then
218-
err_message = "Could not find existing entry (was the ID changed?)"
219-
elseif parsed_entry.name:match("/") or parsed_entry.name:match(fs.sep) then
220-
err_message = "Filename cannot contain path separator"
221-
end
222-
if err_message then
223-
table.insert(errors, {
224-
message = err_message,
225-
lnum = i - 1,
226-
end_lnum = i,
227-
col = 0,
228-
})
229-
goto continue
230-
end
231-
assert(entry)
196+
for i, line in ipairs(lines) do
197+
-- hack to be compatible with Lua 5.1
198+
-- use return instead of goto
199+
(function()
200+
if line:match("^/%d+") then
201+
-- Parse the line for an existing entry
202+
local result, err = M.parse_line(adapter, line, column_defs)
203+
if not result or err then
204+
table.insert(errors, {
205+
message = err,
206+
lnum = i - 1,
207+
end_lnum = i,
208+
col = 0,
209+
})
210+
return
211+
elseif result.data.id == 0 then
212+
-- Ignore entries with ID 0 (typically the "../" entry)
213+
return
214+
end
215+
local parsed_entry = result.data
216+
local entry = result.entry
232217

233-
check_dupe(parsed_entry.name, i)
234-
local meta = entry[FIELD_META]
235-
if original_entries[parsed_entry.name] == parsed_entry.id then
236-
if entry[FIELD_TYPE] == "link" and not compare_link_target(meta, parsed_entry) then
237-
table.insert(diffs, {
238-
type = "new",
239-
name = parsed_entry.name,
240-
entry_type = "link",
241-
link = parsed_entry.link_target,
218+
local err_message
219+
if not parsed_entry.name then
220+
err_message = "No filename found"
221+
elseif not entry then
222+
err_message = "Could not find existing entry (was the ID changed?)"
223+
elseif parsed_entry.name:match("/") or parsed_entry.name:match(fs.sep) then
224+
err_message = "Filename cannot contain path separator"
225+
end
226+
if err_message then
227+
table.insert(errors, {
228+
message = err_message,
229+
lnum = i - 1,
230+
end_lnum = i,
231+
col = 0,
242232
})
243-
elseif entry[FIELD_TYPE] ~= parsed_entry._type then
233+
return
234+
end
235+
assert(entry)
236+
237+
check_dupe(parsed_entry.name, i)
238+
local meta = entry[FIELD_META]
239+
if original_entries[parsed_entry.name] == parsed_entry.id then
240+
if entry[FIELD_TYPE] == "link" and not compare_link_target(meta, parsed_entry) then
241+
table.insert(diffs, {
242+
type = "new",
243+
name = parsed_entry.name,
244+
entry_type = "link",
245+
link = parsed_entry.link_target,
246+
})
247+
elseif entry[FIELD_TYPE] ~= parsed_entry._type then
248+
table.insert(diffs, {
249+
type = "new",
250+
name = parsed_entry.name,
251+
entry_type = parsed_entry._type,
252+
})
253+
else
254+
original_entries[parsed_entry.name] = nil
255+
end
256+
else
244257
table.insert(diffs, {
245258
type = "new",
246259
name = parsed_entry.name,
247260
entry_type = parsed_entry._type,
261+
id = parsed_entry.id,
262+
link = parsed_entry.link_target,
248263
})
249-
else
250-
original_entries[parsed_entry.name] = nil
251264
end
252-
else
253-
table.insert(diffs, {
254-
type = "new",
255-
name = parsed_entry.name,
256-
entry_type = parsed_entry._type,
257-
id = parsed_entry.id,
258-
link = parsed_entry.link_target,
259-
})
260-
end
261265

262-
for _, col_def in ipairs(column_defs) do
263-
local col_name = util.split_config(col_def)
264-
if columns.compare(adapter, col_name, entry, parsed_entry[col_name]) then
265-
table.insert(diffs, {
266-
type = "change",
267-
name = parsed_entry.name,
268-
entry_type = entry[FIELD_TYPE],
269-
column = col_name,
270-
value = parsed_entry[col_name],
266+
for _, col_def in ipairs(column_defs) do
267+
local col_name = util.split_config(col_def)
268+
if columns.compare(adapter, col_name, entry, parsed_entry[col_name]) then
269+
table.insert(diffs, {
270+
type = "change",
271+
name = parsed_entry.name,
272+
entry_type = entry[FIELD_TYPE],
273+
column = col_name,
274+
value = parsed_entry[col_name],
275+
})
276+
end
277+
end
278+
else
279+
-- Parse a new entry
280+
local name, isdir = parsedir(vim.trim(line))
281+
if vim.startswith(name, "/") then
282+
table.insert(errors, {
283+
message = "Paths cannot start with '/'",
284+
lnum = i - 1,
285+
end_lnum = i,
286+
col = 0,
271287
})
288+
return
272289
end
273-
end
274-
else
275-
-- Parse a new entry
276-
local name, isdir = parsedir(vim.trim(line))
277-
if vim.startswith(name, "/") then
278-
table.insert(errors, {
279-
message = "Paths cannot start with '/'",
280-
lnum = i - 1,
281-
end_lnum = i,
282-
col = 0,
283-
})
284-
goto continue
285-
end
286-
if name ~= "" then
287-
local link_pieces = vim.split(name, " -> ", { plain = true })
288-
local entry_type = isdir and "directory" or "file"
289-
local link
290-
if #link_pieces == 2 then
291-
entry_type = "link"
292-
name, link = unpack(link_pieces)
290+
if name ~= "" then
291+
local link_pieces = vim.split(name, " -> ", { plain = true })
292+
local entry_type = isdir and "directory" or "file"
293+
local link
294+
if #link_pieces == 2 then
295+
entry_type = "link"
296+
name, link = unpack(link_pieces)
297+
end
298+
check_dupe(name, i)
299+
table.insert(diffs, {
300+
type = "new",
301+
name = name,
302+
entry_type = entry_type,
303+
link = link,
304+
})
293305
end
294-
check_dupe(name, i)
295-
table.insert(diffs, {
296-
type = "new",
297-
name = name,
298-
entry_type = entry_type,
299-
link = link,
300-
})
301306
end
302-
end
303-
::continue::
307+
end)()
304308
end
305309

306310
for name, child_id in pairs(original_entries) do

lua/oil/view.lua

+10-12
Original file line numberDiff line numberDiff line change
@@ -626,19 +626,17 @@ local function render_buffer(bufnr, opts)
626626
end
627627

628628
for _, entry in ipairs(entry_list) do
629-
if not M.should_display(entry[FIELD_NAME], bufnr) then
630-
goto continue
631-
end
632-
local cols = M.format_entry_cols(entry, column_defs, col_width, adapter)
633-
table.insert(line_table, cols)
634-
635-
local name = entry[FIELD_NAME]
636-
if seek_after_render == name then
637-
seek_after_render_found = true
638-
jump_idx = #line_table
639-
M.set_last_cursor(bufname, nil)
629+
if M.should_display(entry[FIELD_NAME], bufnr) then
630+
local cols = M.format_entry_cols(entry, column_defs, col_width, adapter)
631+
table.insert(line_table, cols)
632+
633+
local name = entry[FIELD_NAME]
634+
if seek_after_render == name then
635+
seek_after_render_found = true
636+
jump_idx = #line_table
637+
M.set_last_cursor(bufname, nil)
638+
end
640639
end
641-
::continue::
642640
end
643641

644642
local lines, highlights = util.render_table(line_table, col_width)

0 commit comments

Comments
 (0)