diff options
| author | Yochem van Rosmalen <git@yochem.nl> | 2025-06-29 17:19:10 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-29 10:19:10 -0500 |
| commit | f7c939fa7af9744bcb6d79100a7e126f7e9c8f5c (patch) | |
| tree | 9e093432a76e557973923009ad7a64251384d0a6 /src/nvim/lua/executor.c | |
| parent | 2f95abddfaf8921555a7e252fc77ed26cbb4de5c (diff) | |
| download | rneovim-f7c939fa7af9744bcb6d79100a7e126f7e9c8f5c.tar.gz rneovim-f7c939fa7af9744bcb6d79100a7e126f7e9c8f5c.tar.bz2 rneovim-f7c939fa7af9744bcb6d79100a7e126f7e9c8f5c.zip | |
fix(exrc): exrc knows its own location (#34638)
fix(exrc): lua exrc files know their location
Problem:
'exrc' files are inherently bound to their location / workspace and
therefore require to "know" their location on the filesystem. However,
currently using `debug.getinfo(1, 'S')` returns `"<nvim>"`.
Solution:
Include the filepath as chunkname in `loadstring()` and `nlua_exec()`.
Diffstat (limited to 'src/nvim/lua/executor.c')
| -rw-r--r-- | src/nvim/lua/executor.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 2f5c7566f4..856dc139af 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1512,17 +1512,20 @@ int typval_exec_lua_callable(LuaRef lua_cb, int argcount, typval_T *argvars, typ /// Used for nvim_exec_lua() and internally to execute a lua string. /// /// @param[in] str String to execute. +/// @param[in] chunkname Chunkname, defaults to "<nvim>". /// @param[in] args array of ... args /// @param[in] mode Whether and how the the return value should be converted to Object /// @param[in] arena can be NULL, then nested allocations are used /// @param[out] err Location where error will be saved. /// /// @return Return value of the execution. -Object nlua_exec(const String str, const Array args, LuaRetMode mode, Arena *arena, Error *err) +Object nlua_exec(const String str, const char *chunkname, const Array args, LuaRetMode mode, + Arena *arena, Error *err) { lua_State *const lstate = global_lstate; - if (luaL_loadbuffer(lstate, str.data, str.size, "<nvim>")) { + const char *name = (chunkname && chunkname[0]) ? chunkname : "<nvim>"; + if (luaL_loadbuffer(lstate, str.data, str.size, name)) { size_t len; const char *errstr = lua_tolstring(lstate, -1, &len); api_set_error(err, kErrorTypeValidation, "Lua: %.*s", (int)len, errstr); |