diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2019-09-28 18:35:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-28 18:35:02 +0200 |
commit | e933426299b44db6715f6f61ab76aee57478110e (patch) | |
tree | ffca71781f4e06460fa9b98be68cb02a23d5e0bd /src/nvim/lua/executor.c | |
parent | 0d9a3c86a1c7143187398e6cb6005ed06a5e2fde (diff) | |
parent | 9fa850991dbe8984996afdc149b5b32dc248197e (diff) | |
download | rneovim-e933426299b44db6715f6f61ab76aee57478110e.tar.gz rneovim-e933426299b44db6715f6f61ab76aee57478110e.tar.bz2 rneovim-e933426299b44db6715f6f61ab76aee57478110e.zip |
Merge pull request #10124 from bfredl/tree-sitter-api
Tree-sitter step 1: vendor runtime lib + add lua API
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r-- | src/nvim/lua/executor.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index f51aa3c6d4..127458fe39 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -31,6 +31,7 @@ #include "nvim/lua/executor.h" #include "nvim/lua/converter.h" +#include "nvim/lua/treesitter.h" #include "luv/luv.h" @@ -310,7 +311,11 @@ static int nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL lua_setfield(lstate, -2, "luv"); lua_pop(lstate, 3); + // internal vim._treesitter... API + nlua_add_treesitter(lstate); + lua_setglobal(lstate, "vim"); + return 0; } @@ -816,3 +821,27 @@ void ex_luafile(exarg_T *const eap) return; } } + +static int create_tslua_parser(lua_State *L) +{ + if (lua_gettop(L) < 1 || !lua_isstring(L, 1)) { + return luaL_error(L, "string expected"); + } + + const char *lang_name = lua_tostring(L, 1); + return tslua_push_parser(L, lang_name); +} + +static void nlua_add_treesitter(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL +{ + tslua_init(lstate); + + lua_pushcfunction(lstate, create_tslua_parser); + lua_setfield(lstate, -2, "_create_ts_parser"); + + lua_pushcfunction(lstate, tslua_register_lang); + lua_setfield(lstate, -2, "_ts_add_language"); + + lua_pushcfunction(lstate, tslua_inspect_lang); + lua_setfield(lstate, -2, "_ts_inspect_language"); +} |