示例工程 33-neovim-and-love

33-neovim-and-love/01-nvim-module/main.lua

lua · 0.5 KB

-- @runtimes lua54
--- 演示:Neovim 插件的纯逻辑 + stub vim。
local M = {}
 
local function greeting(vim, name)
	vim.api.nvim_out_write("hello " .. name .. "\n")
	return "hello " .. name
end
 
--- @return table { text = string }
function M.run(log)
	log = log or print
	local output = {}
	local vim = {
		api = {
			nvim_out_write = function(text)
				output[#output + 1] = text
			end,
		},
	}
	local text = greeting(vim, "Ada")
	log(("text=%s writes=%d"):format(text, #output))
	return { text = text }
end
if not ... then
	M.run()
end
return M