mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 00:08:19 +00:00
treesitter: simplify puhstree call process
This commit is contained in:
@@ -1128,21 +1128,11 @@ void ex_luafile(exarg_T *const eap)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
static void nlua_add_treesitter(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
tslua_init(lstate);
|
tslua_init(lstate);
|
||||||
|
|
||||||
lua_pushcfunction(lstate, create_tslua_parser);
|
lua_pushcfunction(lstate, tslua_push_parser);
|
||||||
lua_setfield(lstate, -2, "_create_ts_parser");
|
lua_setfield(lstate, -2, "_create_ts_parser");
|
||||||
|
|
||||||
lua_pushcfunction(lstate, tslua_add_language);
|
lua_pushcfunction(lstate, tslua_add_language);
|
||||||
|
@@ -214,8 +214,14 @@ int tslua_inspect_lang(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tslua_push_parser(lua_State *L, const char *lang_name)
|
int tslua_push_parser(lua_State *L)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Gather language
|
||||||
|
if (lua_gettop(L) < 1 || !lua_isstring(L, 1)) {
|
||||||
|
return luaL_error(L, "string expected");
|
||||||
|
}
|
||||||
|
const char *lang_name = lua_tostring(L, 1);
|
||||||
TSLanguage *lang = pmap_get(cstr_t)(langs, lang_name);
|
TSLanguage *lang = pmap_get(cstr_t)(langs, lang_name);
|
||||||
if (!lang) {
|
if (!lang) {
|
||||||
return luaL_error(L, "no such language: %s", lang_name);
|
return luaL_error(L, "no such language: %s", lang_name);
|
||||||
|
Reference in New Issue
Block a user