diff options
author | TJ DeVries <devries.timothyj@gmail.com> | 2020-08-14 10:03:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-14 10:03:17 -0400 |
commit | 3ccdbc570d856ee3ff1f64204e352a40b9030ac2 (patch) | |
tree | e73d198bef4dce52bfd990dc57ea419e8b1fc703 /src/nvim/lua/executor.c | |
parent | aa48c1c724f7164485782a3a5a8ff7a94373f607 (diff) | |
download | rneovim-3ccdbc570d856ee3ff1f64204e352a40b9030ac2.tar.gz rneovim-3ccdbc570d856ee3ff1f64204e352a40b9030ac2.tar.bz2 rneovim-3ccdbc570d856ee3ff1f64204e352a40b9030ac2.zip |
lua: add vim.register_keystroke_callback (#12536)
* feat: Add vim.register_keystroke_callback
* fixup: Forgot to remove mention of old option
* fixup: Answer jamessan comments
* fixup: Answer norcalli comments
* fixup: portability
* Update runtime/doc/lua.txt
Co-authored-by: Ashkan Kiani <ashkan.k.kiani@gmail.com>
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r-- | src/nvim/lua/executor.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 86da517685..5ad9731a97 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1465,3 +1465,40 @@ void nlua_free_typval_dict(dict_T *const d) d->lua_table_ref = LUA_NOREF; } } + +void nlua_execute_log_keystroke(int c) +{ + char_u buf[NUMBUFLEN]; + size_t buf_len = special_to_buf(c, mod_mask, false, buf); + + lua_State *const lstate = nlua_enter(); + +#ifndef NDEBUG + int top = lua_gettop(lstate); +#endif + + // [ vim ] + lua_getglobal(lstate, "vim"); + + // [ vim, vim._log_keystroke ] + lua_getfield(lstate, -1, "_log_keystroke"); + luaL_checktype(lstate, -1, LUA_TFUNCTION); + + // [ vim, vim._log_keystroke, buf ] + lua_pushlstring(lstate, (const char *)buf, buf_len); + + if (lua_pcall(lstate, 1, 0, 0)) { + nlua_error( + lstate, + _("Error executing vim.log_keystroke lua callback: %.*s")); + } + + // [ vim ] + lua_pop(lstate, 1); + +#ifndef NDEBUG + // [ ] + assert(top == lua_gettop(lstate)); +#endif +} + |