From c407d30856f3a4af800cc2dd2f319be903381705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 7 Nov 2015 16:07:35 +0100 Subject: vis: introduce vis namespace for lua objects For now the vis table has only one member "lexers". --- lexers/themes/solarized.lua | 2 ++ view.c | 16 +++++++--------- vis.c | 8 ++++++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lexers/themes/solarized.lua b/lexers/themes/solarized.lua index dee1750..4264f15 100644 --- a/lexers/themes/solarized.lua +++ b/lexers/themes/solarized.lua @@ -1,4 +1,6 @@ -- Solarized color codes Copyright (c) 2011 Ethan Schoonover +local lexers = vis.lexers + local colors = { ['base03'] = '#000000', -- '#002b36', ['base02'] = '#073642', diff --git a/view.c b/view.c index f7f393a..cc60f86 100644 --- a/view.c +++ b/view.c @@ -456,7 +456,8 @@ void view_update(View *view) { lua_State *L = view->lua; if (L && view->lexer_name) { - lua_getglobal(L, "lexers"); + lua_getglobal(L, "vis"); + lua_getfield(L, -1, "lexers"); lua_getfield(L, -1, "load"); lua_pushstring(L, view->lexer_name); lua_pcall(L, 1, 1, 0); @@ -898,11 +899,12 @@ bool view_syntax_set(View *view, const char *name) { /* Try to load the specified lexer and parse its token styles. * Roughly equivalent to the following lua code: * - * lang = lexers.load(name) + * lang = vis.lexers.load(name) * for token_name, id in pairs(lang._TOKENSTYLES) do - * ui->syntax_style(id, lexers:get_style(lang, token_name); + * ui->syntax_style(id, vis.lexers:get_style(lang, token_name); */ - lua_getglobal(L, "lexers"); + lua_getglobal(L, "vis"); + lua_getfield(L, -1, "lexers"); lua_getfield(L, -1, "STYLE_DEFAULT"); view->ui->syntax_style(view->ui, UI_STYLE_DEFAULT, lua_tostring(L, -1)); @@ -923,7 +925,6 @@ bool view_syntax_set(View *view, const char *name) { view->ui->syntax_style(view->ui, UI_STYLE_COLOR_COLUMN, lua_tostring(L, -1)); lua_pop(L, 1); - lua_getfield(L, -1, "load"); lua_pushstring(L, name); @@ -956,10 +957,7 @@ bool view_syntax_set(View *view, const char *name) { lua_pop(L, 1); /* style */ } - lua_pop(L, 1); /* _TOKENSTYLES */ - lua_pop(L, 1); /* grammar */ - - lua_pop(L, 1); /* lexers */ + lua_pop(L, 4); /* _TOKENSTYLES, grammar, lexers, vis */ return true; } diff --git a/vis.c b/vis.c index 12f3b19..dc56fb3 100644 --- a/vis.c +++ b/vis.c @@ -132,7 +132,8 @@ void vis_window_name(Win *win, const char *filename) { } if (filename && L) { - lua_getglobal(L, "lexers"); + lua_getglobal(L, "vis"); + lua_getfield(L, -1, "lexers"); lua_getfield(L, -1, "lexer_name"); lua_pushstring(L, filename); lua_pcall(L, 1, 1, 0); @@ -360,7 +361,10 @@ Vis *vis_new(Ui *ui) { lua_close(L); vis->lua = L = NULL; } else { - lua_setglobal(L, "lexers"); + lua_newtable(L); /* vis */ + lua_pushvalue(L, -2); /* require return value */ + lua_setfield(L, -2, "lexers"); + lua_setglobal(L, "vis"); vis_theme_load(vis, "default"); } -- cgit v1.2.3