mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 06:48:17 +00:00
feat(lua): make =expr print result of expr
This commit is contained in:
@@ -1115,11 +1115,23 @@ void ex_lua(exarg_T *const eap)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
size_t len;
|
||||
char *const code = script_get(eap, &len);
|
||||
char *code = script_get(eap, &len);
|
||||
if (eap->skip) {
|
||||
xfree(code);
|
||||
return;
|
||||
}
|
||||
// When =expr is used transform it to print(vim.inspect(expr))
|
||||
if (code[0] == '=') {
|
||||
len += sizeof("print(vim.inspect())") - sizeof("=");
|
||||
// code_buf needs to be 1 char larger then len for null byte in the end.
|
||||
// lua nlua_typval_exec doesn't expect null terminated string so len
|
||||
// needs to end before null byte.
|
||||
char *code_buf = xmallocz(len);
|
||||
vim_snprintf(code_buf, len+1, "print(vim.inspect(%s))", code+1);
|
||||
xfree(code);
|
||||
code = code_buf;
|
||||
}
|
||||
|
||||
nlua_typval_exec(code, len, ":lua", NULL, 0, false, NULL);
|
||||
|
||||
xfree(code);
|
||||
|
Reference in New Issue
Block a user