aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua/executor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r--src/nvim/lua/executor.c43
1 files changed, 19 insertions, 24 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index 1a9bd026b5..a76b8213e5 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -103,7 +103,7 @@ typedef struct {
if (args[i].v_type == VAR_UNKNOWN) { \
lua_pushnil(lstate); \
} else { \
- nlua_push_typval(lstate, &args[i], special); \
+ nlua_push_typval(lstate, &args[i], (special) ? kNluaPushSpecial : 0); \
} \
}
@@ -325,7 +325,7 @@ static int nlua_thr_api_nvim__get_runtime(lua_State *lstate)
}
ArrayOf(String) ret = runtime_get_named_thread(is_lua, pat, all);
- nlua_push_Array(lstate, ret, true);
+ nlua_push_Array(lstate, ret, kNluaPushSpecial);
api_free_array(ret);
api_free_array(pat);
@@ -1210,7 +1210,7 @@ int nlua_call(lua_State *lstate)
});
if (!ERROR_SET(&err)) {
- nlua_push_typval(lstate, &rettv, false);
+ nlua_push_typval(lstate, &rettv, 0);
}
tv_clear(&rettv);
@@ -1261,7 +1261,7 @@ static int nlua_rpc(lua_State *lstate, bool request)
ArenaMem res_mem = NULL;
Object result = rpc_send_call(chan_id, name, args, &res_mem, &err);
if (!ERROR_SET(&err)) {
- nlua_push_Object(lstate, &result, false);
+ nlua_push_Object(lstate, &result, 0);
arena_mem_free(res_mem);
}
} else {
@@ -1487,7 +1487,7 @@ static void nlua_typval_exec(const char *lcmd, size_t lcmd_len, const char *name
}
}
-int nlua_source_using_linegetter(LineGetter fgetline, void *cookie, char *name)
+void nlua_source_str(const char *code, char *name)
{
const sctx_T save_current_sctx = current_sctx;
current_sctx.sc_sid = SID_STR;
@@ -1495,22 +1495,11 @@ int nlua_source_using_linegetter(LineGetter fgetline, void *cookie, char *name)
current_sctx.sc_lnum = 0;
estack_push(ETYPE_SCRIPT, name, 0);
- garray_T ga;
- char *line = NULL;
-
- ga_init(&ga, (int)sizeof(char *), 10);
- while ((line = fgetline(0, cookie, 0, false)) != NULL) {
- GA_APPEND(char *, &ga, line);
- }
- char *code = ga_concat_strings_sep(&ga, "\n");
size_t len = strlen(code);
nlua_typval_exec(code, len, name, NULL, 0, false, NULL);
estack_pop();
current_sctx = save_current_sctx;
- ga_clear_strings(&ga);
- xfree(code);
- return OK;
}
/// Call a LuaCallable given some typvals
@@ -1564,7 +1553,7 @@ Object nlua_exec(const String str, const Array args, LuaRetMode mode, Arena *are
}
for (size_t i = 0; i < args.size; i++) {
- nlua_push_Object(lstate, &args.items[i], false);
+ nlua_push_Object(lstate, &args.items[i], 0);
}
if (nlua_pcall(lstate, (int)args.size, 1)) {
@@ -1611,7 +1600,7 @@ Object nlua_call_ref(LuaRef ref, const char *name, Array args, LuaRetMode mode,
nargs++;
}
for (size_t i = 0; i < args.size; i++) {
- nlua_push_Object(lstate, &args.items[i], false);
+ nlua_push_Object(lstate, &args.items[i], 0);
}
if (nlua_pcall(lstate, nargs, 1)) {
@@ -1767,7 +1756,7 @@ void ex_luado(exarg_T *const eap)
lua_pushvalue(lstate, -1);
const char *const old_line = ml_get_buf(curbuf, l);
// Get length of old_line here as calling Lua code may free it.
- const size_t old_line_len = strlen(old_line);
+ const colnr_T old_line_len = ml_get_buf_len(curbuf, l);
lua_pushstring(lstate, old_line);
lua_pushnumber(lstate, (lua_Number)l);
if (nlua_pcall(lstate, 2, 1)) {
@@ -1791,13 +1780,13 @@ void ex_luado(exarg_T *const eap)
}
}
ml_replace(l, new_line_transformed, false);
- inserted_bytes(l, 0, (int)old_line_len, (int)new_line_len);
+ inserted_bytes(l, 0, old_line_len, (int)new_line_len);
}
lua_pop(lstate, 1);
}
lua_pop(lstate, 1);
- check_cursor();
+ check_cursor(curwin);
redraw_curbuf_later(UPD_NOT_VALID);
}
@@ -1909,6 +1898,9 @@ static void nlua_add_treesitter(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
lua_pushcfunction(lstate, tslua_push_parser);
lua_setfield(lstate, -2, "_create_ts_parser");
+ lua_pushcfunction(lstate, tslua_push_querycursor);
+ lua_setfield(lstate, -2, "_create_ts_querycursor");
+
lua_pushcfunction(lstate, tslua_add_language);
lua_setfield(lstate, -2, "_ts_add_language");
@@ -2061,9 +2053,9 @@ char *nlua_register_table_as_callable(const typval_T *const arg)
return name;
}
-void nlua_execute_on_key(int c)
+void nlua_execute_on_key(int c, char *typed_buf, size_t typed_len)
{
- char buf[NUMBUFLEN];
+ char buf[MB_MAXBYTES * 3 + 4];
size_t buf_len = special_to_buf(c, mod_mask, false, buf);
lua_State *const lstate = global_lstate;
@@ -2082,9 +2074,12 @@ void nlua_execute_on_key(int c)
// [ vim, vim._on_key, buf ]
lua_pushlstring(lstate, buf, buf_len);
+ // [ vim, vim._on_key, buf, typed_buf ]
+ lua_pushlstring(lstate, typed_buf, typed_len);
+
int save_got_int = got_int;
got_int = false; // avoid interrupts when the key typed is Ctrl-C
- if (nlua_pcall(lstate, 1, 0)) {
+ if (nlua_pcall(lstate, 2, 0)) {
nlua_error(lstate,
_("Error executing vim.on_key Lua callback: %.*s"));
}