diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-02-18 15:05:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-18 15:05:50 +0100 |
commit | 5064ff126dcd3ef2924c6c5aeebda64fc43fc5ea (patch) | |
tree | a544ef288fb972072574aa9fdbdfa7b826839acd /src/nvim/lua/executor.c | |
parent | 720bb5844de76e06b3ece60c92b4d7877e7c4143 (diff) | |
parent | adad10284d8e0e7d15189181a061b6b665663467 (diff) | |
download | rneovim-5064ff126dcd3ef2924c6c5aeebda64fc43fc5ea.tar.gz rneovim-5064ff126dcd3ef2924c6c5aeebda64fc43fc5ea.tar.bz2 rneovim-5064ff126dcd3ef2924c6c5aeebda64fc43fc5ea.zip |
Merge pull request #17200 from lewis6991/_loadfile
refactor(lua): call `loadfile` internally instead of `luaL_loadfile`
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r-- | src/nvim/lua/executor.c | 24 |
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; |