📜  nvim lua - init.lua - 要求不存在的模块或包含语法错误的模块会中止当前执行的脚本. pcall() 可用于防止错误. - 无论代码示例

📅  最后修改于: 2022-03-11 14:58:39.292000             🧑  作者: Mango

代码示例1
-- Protected Lua Call to Require Module (vscode style snippet + output)

-- Snippet
"Protected Lua Call to Require Module": {
  "prefix": "prlua",
  "body": [
    "local ${1:module}_status_ok, ${1:module} = pcall(require, \"${1:module}\")",
    "if not ${1:module}_status_ok then",
    "  return",
    "end",
    ""
  ],
  "description": "Protected Lua Call to Require Module"
}

-- Output
local module_status_ok, module = pcall(require, "module")
if not module_status_ok then
  return
end