aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval/funcs.c2
-rw-r--r--src/nvim/lua/executor.c18
2 files changed, 20 insertions, 0 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index c35e0b2ada..1468c5564e 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -1716,6 +1716,8 @@ static void f_exists(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
} else {
n = au_exists(p + 1);
}
+ } else if (strncmp(p, "v:lua.", 6) == 0 && nlua_func_exists(p + 6)) {
+ n = true;
} else { // Internal variable.
n = var_exists(p);
}
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index e665732c1a..e0bdbbc1e9 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -2313,3 +2313,21 @@ void nlua_init_defaults(void)
os_errmsg("\n");
}
}
+
+/// check lua function exist
+bool nlua_func_exists(const char *lua_funcname)
+{
+ MAXSIZE_TEMP_ARRAY(args, 1);
+ size_t length = strlen(lua_funcname) + 8;
+ char *str = xmalloc(length);
+ vim_snprintf(str, length, "return %s", lua_funcname);
+ ADD_C(args, CSTR_AS_OBJ(str));
+ Error err = ERROR_INIT;
+ Object result = NLUA_EXEC_STATIC("return type(loadstring(...)()) =='function'", args, &err);
+ xfree(str);
+
+ if (result.type != kObjectTypeBoolean) {
+ return false;
+ }
+ return result.data.boolean;
+}