I want to assemble a table based on the values of other tables. For this I'm unpacking a two tables into the new table. Here's what I have
local function assemble_abspath_candidates()
-- Make sure user data path preceedes the system paths
local user_data = vim.fn.stdpath('data')
local data_dirs = vim.fn.stdpath('data_dirs')
-- Make sure user config path preceedes system config paths
local user_config = vim.fn.stdpath('config')
local config_dirs = vim.fn.stdpath('config_dirs')
-- Print data_dirs
for i, val in ipairs(data_dirs) do
vim.print("datadir " .. i .. ": " .. val)
end
-- Print config dirs
for i, val in ipairs(config_dirs) do
vim.print("config dir " .. i .. ": " .. val)
end
local combined_paths = { user_data, user_config, unpack(data_dirs), unpack(config_dirs) }
-- Print it all
for i, val in ipairs(combined_paths) do
vim.print(i .. ": " .. val)
end
return combined_paths
end
The outcome of this however is not how I expected it:
datadir 1: /usr/share/i3/nvim
datadir 2: /usr/share/gnome/nvim
datadir 3: /usr/local/share/nvim
datadir 4: /usr/share/nvim
datadir 5: /var/lib/snapd/desktop/nvim
config dir 1: /etc/xdg/xdg-i3/nvim
config dir 2: /etc/xdg/nvim
1: /home/myuser/.local/share/nvim
2: /home/myuser/.config/nvim
3: /usr/share/i3/nvim
4: /etc/xdg/xdg-i3/nvim
5: /etc/xdg/nvim
For some reason only the first value from datadir is taken. Why does this happen?
The question is different from unpack as function argument since I don't call a function but I want to expand a table using the unpack results (which according to this documentation should result in the expanded values being reimagined as table elements).
I suppose this is also the use case for unpack, or what else would be? And it even works for one of the unpacks, but just not for both at the same time..
(NVIM v0.11.0-dev-1161+g6ef80eb42c LUA 5.1 interpreter)