run function with noautocmd:
local function noautocmd(f)
local save_ei = vim.o.eventignore
pcall(f)
vim.o.eventignore = save_ei
end
noautocmd(function()
-- do something here
end)
Lua 可变参数使用示例:
local function test(...)
print(...)
-- 可变参数长度
print(select('#', ...))
-- 访问第 n 个参数
print(select(2, ...))
local a = select(2, ...)
print(a)
end
test('a', 'b', 'c')
lua 字符串载入:
local function eval_str(equation, variables)
if(type(equation) == "string") then
local eval = loadstring("return "..equation);
if(type(eval) == "function") then
setfenv(eval, variables or {});
return eval();
end
end
end
local str = '200 + v * 10 - 1 * 288 * 20'
print(eval_str(str, { v=1}))