aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2022-01-26 10:23:59 +0000
committerLewis Russell <lewis6991@gmail.com>2022-02-18 10:39:45 +0000
commitadad10284d8e0e7d15189181a061b6b665663467 (patch)
treeff1ea67b6dccb5c5a2ba9133c4946cf2c4850419
parentfaeff49cbfd190afba67e221412b7132b7ad8360 (diff)
downloadrneovim-adad10284d8e0e7d15189181a061b6b665663467.tar.gz
rneovim-adad10284d8e0e7d15189181a061b6b665663467.tar.bz2
rneovim-adad10284d8e0e7d15189181a061b6b665663467.zip
refactor(lua): call loadfile internally
.. instead of luaL_loadfile allows files to be cached
-rw-r--r--src/nvim/lua/executor.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index cbfb8364f6..029e7eb660 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -1241,6 +1241,9 @@ void ex_luafile(exarg_T *const eap)
/// execute lua code from a file.
///
+/// Note: we call the lua global loadfile as opposed to calling luaL_loadfile
+/// in case loadfile has been overridden in the users environment.
+///
/// @param path path of the file
///
/// @return true if everything ok, false if there was an error (echoed)
@@ -1249,11 +1252,30 @@ bool nlua_exec_file(const char *path)
{
lua_State *const lstate = global_lstate;
- if (luaL_loadfile(lstate, path)) {
+ lua_getglobal(lstate, "loadfile");
+ lua_pushstring(lstate, path);
+
+ if (nlua_pcall(lstate, 1, 2)) {
+ nlua_error(lstate, _("E5111: Error calling lua: %.*s"));
+ return false;
+ }
+
+ // loadstring() returns either:
+ // 1. nil, error
+ // 2. chunk, nil
+
+ if (lua_isnil(lstate, -2)) {
+ // 1
nlua_error(lstate, _("E5112: Error while creating lua chunk: %.*s"));
+ assert(lua_isnil(lstate, -1));
+ lua_pop(lstate, 1);
return false;
}
+ // 2
+ assert(lua_isnil(lstate, -1));
+ lua_pop(lstate, 1);
+
if (nlua_pcall(lstate, 0, 0)) {
nlua_error(lstate, _("E5113: Error while calling lua chunk: %.*s"));
return false;