aboutsummaryrefslogtreecommitdiff
path: root/vis-lua.c
diff options
context:
space:
mode:
authorRandy Palamar <randy@rnpnr.xyz>2024-05-21 11:27:08 -0600
committerRandy Palamar <randy@rnpnr.xyz>2024-05-21 20:21:46 -0600
commit7554ecd77efc29601b7b44deca602724917ce019 (patch)
tree9e8e7d0ca7f0b173f98c224a25f6f626dcece8ac /vis-lua.c
parent7e85064ac77ea43e84d88eb910b0adb6f07d5d12 (diff)
downloadvis-7554ecd77efc29601b7b44deca602724917ce019.tar.gz
vis-7554ecd77efc29601b7b44deca602724917ce019.tar.xz
remove some view pointer chasing
Same as previous commit each window only has a single View. No need for it to be stored elsewhere in memory.
Diffstat (limited to 'vis-lua.c')
-rw-r--r--vis-lua.c74
1 files changed, 37 insertions, 37 deletions
diff --git a/vis-lua.c b/vis-lua.c
index 6bd8a08..75e2e24 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -1107,7 +1107,7 @@ static bool command_lua(Vis *vis, Win *win, void *data, bool force, const char *
if (!obj_ref_new(L, win, VIS_LUA_TYPE_WINDOW))
return false;
if (!sel)
- sel = view_selections_primary_get(win->view);
+ sel = view_selections_primary_get(&win->view);
if (!obj_lightref_new(L, sel, VIS_LUA_TYPE_SELECTION))
return false;
pushrange(L, range);
@@ -1766,8 +1766,8 @@ static int window_index(lua_State *L) {
if (strcmp(key, "viewport") == 0) {
Filerange b = VIEW_VIEWPORT_GET(win->view);
Filerange l;
- l.start = win->view->topline->lineno;
- l.end = win->view->lastline->lineno;
+ l.start = win->view.topline->lineno;
+ l.end = win->view.lastline->lineno;
lua_createtable(L, 0, 4);
lua_pushstring(L, "bytes");
@@ -1777,10 +1777,10 @@ static int window_index(lua_State *L) {
pushrange(L, &l);
lua_settable(L, -3);
lua_pushstring(L, "width");
- lua_pushunsigned(L, win->view->width);
+ lua_pushunsigned(L, win->view.width);
lua_settable(L, -3);
lua_pushstring(L, "height");
- lua_pushunsigned(L, win->view->height);
+ lua_pushunsigned(L, win->view.height);
lua_settable(L, -3);
return 1;
}
@@ -1801,13 +1801,13 @@ static int window_index(lua_State *L) {
}
if (strcmp(key, "selection") == 0) {
- Selection *sel = view_selections_primary_get(win->view);
+ Selection *sel = view_selections_primary_get(&win->view);
obj_lightref_new(L, sel, VIS_LUA_TYPE_SELECTION);
return 1;
}
if (strcmp(key, "selections") == 0) {
- obj_ref_new(L, win->view, VIS_LUA_TYPE_SELECTIONS);
+ obj_ref_new(L, &win->view, VIS_LUA_TYPE_SELECTIONS);
return 1;
}
@@ -1825,64 +1825,64 @@ static int window_index(lua_State *L) {
}
static int window_options_assign(Win *win, lua_State *L, const char *key, int next) {
- enum UiOption flags = UI_OPTIONS_GET(win->view->ui);
+ enum UiOption flags = UI_OPTIONS_GET(win->view.ui);
if (strcmp(key, "breakat") == 0 || strcmp(key, "brk") == 0) {
if (lua_isstring(L, next))
- view_breakat_set(win->view, lua_tostring(L, next));
+ view_breakat_set(&win->view, lua_tostring(L, next));
} else if (strcmp(key, "colorcolumn") == 0 || strcmp(key, "cc") == 0) {
- win->view->colorcolumn = luaL_checkunsigned(L, next);
+ win->view.colorcolumn = luaL_checkunsigned(L, next);
} else if (strcmp(key, "cursorline") == 0 || strcmp(key, "cul") == 0) {
if (lua_toboolean(L, next))
flags |= UI_OPTION_CURSOR_LINE;
else
flags &= ~UI_OPTION_CURSOR_LINE;
- view_options_set(win->view, flags);
+ view_options_set(&win->view, flags);
} else if (strcmp(key, "numbers") == 0 || strcmp(key, "nu") == 0) {
if (lua_toboolean(L, next))
flags |= UI_OPTION_LINE_NUMBERS_ABSOLUTE;
else
flags &= ~UI_OPTION_LINE_NUMBERS_ABSOLUTE;
- view_options_set(win->view, flags);
+ view_options_set(&win->view, flags);
} else if (strcmp(key, "relativenumbers") == 0 || strcmp(key, "rnu") == 0) {
if (lua_toboolean(L, next))
flags |= UI_OPTION_LINE_NUMBERS_RELATIVE;
else
flags &= ~UI_OPTION_LINE_NUMBERS_RELATIVE;
- view_options_set(win->view, flags);
+ view_options_set(&win->view, flags);
} else if (strcmp(key, "showeof") == 0) {
if (lua_toboolean(L, next))
flags |= UI_OPTION_SYMBOL_EOF;
else
flags &= ~UI_OPTION_SYMBOL_EOF;
- view_options_set(win->view, flags);
+ view_options_set(&win->view, flags);
} else if (strcmp(key, "shownewlines") == 0) {
if (lua_toboolean(L, next))
flags |= UI_OPTION_SYMBOL_EOL;
else
flags &= ~UI_OPTION_SYMBOL_EOL;
- view_options_set(win->view, flags);
+ view_options_set(&win->view, flags);
} else if (strcmp(key, "showspaces") == 0) {
if (lua_toboolean(L, next))
flags |= UI_OPTION_SYMBOL_SPACE;
else
flags &= ~UI_OPTION_SYMBOL_SPACE;
- view_options_set(win->view, flags);
+ view_options_set(&win->view, flags);
} else if (strcmp(key, "showtabs") == 0) {
if (lua_toboolean(L, next))
flags |= UI_OPTION_SYMBOL_TAB;
else
flags &= ~UI_OPTION_SYMBOL_TAB;
- view_options_set(win->view, flags);
+ view_options_set(&win->view, flags);
} else if (strcmp(key, "statusbar") == 0) {
if (lua_toboolean(L, next))
flags |= UI_OPTION_STATUSBAR;
else
flags &= ~UI_OPTION_STATUSBAR;
- view_options_set(win->view, flags);
+ view_options_set(&win->view, flags);
} else if (strcmp(key, "wrapcolumn") == 0 || strcmp(key, "wc") == 0) {
- win->view->wrapcolumn = luaL_checkunsigned(L, next);
+ win->view.wrapcolumn = luaL_checkunsigned(L, next);
} else if (strcmp(key, "tabwidth") == 0 || strcmp(key, "tw") == 0) {
- view_tabwidth_set(win->view, luaL_checkint(L, next));
+ view_tabwidth_set(&win->view, luaL_checkint(L, next));
} else if (strcmp(key, "expandtab") == 0 || strcmp(key, "et") == 0) {
win->expandtab = lua_toboolean(L, next);
}
@@ -1942,7 +1942,7 @@ static int window_selections_iterator_next(lua_State *L) {
static int window_selections_iterator(lua_State *L) {
Win *win = obj_ref_check(L, 1, VIS_LUA_TYPE_WINDOW);
Selection **handle = lua_newuserdata(L, sizeof *handle);
- *handle = view_selections(win->view);
+ *handle = view_selections(&win->view);
lua_pushcclosure(L, window_selections_iterator_next, 1);
return 1;
}
@@ -1986,7 +1986,7 @@ static int window_style_define(lua_State *L) {
Win *win = obj_ref_check(L, 1, VIS_LUA_TYPE_WINDOW);
enum UiStyle id = luaL_checkunsigned(L, 2);
const char *style = luaL_checkstring(L, 3);
- bool ret = ui_style_define(win->view->ui, id, style);
+ bool ret = ui_style_define(win->view.ui, id, style);
lua_pushboolean(L, ret);
return 1;
}
@@ -2008,7 +2008,7 @@ static int window_style(lua_State *L) {
enum UiStyle style = luaL_checkunsigned(L, 2);
size_t start = checkpos(L, 3);
size_t end = checkpos(L, 4);
- view_style(win->view, style, start, end);
+ view_style(&win->view, style, start, end);
return 0;
}
@@ -2068,7 +2068,7 @@ static int window_status(lua_State *L) {
*/
static int window_draw(lua_State *L) {
Win *win = obj_ref_check(L, 1, VIS_LUA_TYPE_WINDOW);
- view_draw(win->view);
+ view_draw(&win->view);
return 0;
}
@@ -2140,43 +2140,43 @@ static int window_options_index(lua_State *L) {
if (lua_isstring(L, 2)) {
const char *key = lua_tostring(L, 2);
if (strcmp(key, "breakat") == 0 || strcmp(key, "brk") == 0) {
- lua_pushstring(L, win->view->breakat);
+ lua_pushstring(L, win->view.breakat);
return 1;
} else if (strcmp(key, "colorcolumn") == 0 || strcmp(key, "cc") == 0) {
- lua_pushunsigned(L, win->view->colorcolumn);
+ lua_pushunsigned(L, win->view.colorcolumn);
return 1;
} else if (strcmp(key, "cursorline") == 0 || strcmp(key, "cul") == 0) {
- lua_pushboolean(L, UI_OPTIONS_GET(win->view->ui) & UI_OPTION_CURSOR_LINE);
+ lua_pushboolean(L, UI_OPTIONS_GET(win->view.ui) & UI_OPTION_CURSOR_LINE);
return 1;
} else if (strcmp(key, "expandtab") == 0 || strcmp(key, "et") == 0) {
lua_pushboolean(L, win->expandtab);
return 1;
} else if (strcmp(key, "numbers") == 0 || strcmp(key, "nu") == 0) {
- lua_pushboolean(L, UI_OPTIONS_GET(win->view->ui) & UI_OPTION_LINE_NUMBERS_ABSOLUTE);
+ lua_pushboolean(L, UI_OPTIONS_GET(win->view.ui) & UI_OPTION_LINE_NUMBERS_ABSOLUTE);
return 1;
} else if (strcmp(key, "relativenumbers") == 0 || strcmp(key, "rnu") == 0) {
- lua_pushboolean(L, UI_OPTIONS_GET(win->view->ui) & UI_OPTION_LINE_NUMBERS_RELATIVE);
+ lua_pushboolean(L, UI_OPTIONS_GET(win->view.ui) & UI_OPTION_LINE_NUMBERS_RELATIVE);
return 1;
} else if (strcmp(key, "showeof") == 0) {
- lua_pushboolean(L, UI_OPTIONS_GET(win->view->ui) & UI_OPTION_SYMBOL_EOF);
+ lua_pushboolean(L, UI_OPTIONS_GET(win->view.ui) & UI_OPTION_SYMBOL_EOF);
return 1;
} else if (strcmp(key, "shownewlines") == 0) {
- lua_pushboolean(L, UI_OPTIONS_GET(win->view->ui) & UI_OPTION_SYMBOL_EOL);
+ lua_pushboolean(L, UI_OPTIONS_GET(win->view.ui) & UI_OPTION_SYMBOL_EOL);
return 1;
} else if (strcmp(key, "showspaces") == 0) {
- lua_pushboolean(L, UI_OPTIONS_GET(win->view->ui) & UI_OPTION_SYMBOL_SPACE);
+ lua_pushboolean(L, UI_OPTIONS_GET(win->view.ui) & UI_OPTION_SYMBOL_SPACE);
return 1;
} else if (strcmp(key, "showtabs") == 0) {
- lua_pushboolean(L, UI_OPTIONS_GET(win->view->ui) & UI_OPTION_SYMBOL_TAB);
+ lua_pushboolean(L, UI_OPTIONS_GET(win->view.ui) & UI_OPTION_SYMBOL_TAB);
return 1;
} else if (strcmp(key, "statusbar") == 0) {
- lua_pushboolean(L, UI_OPTIONS_GET(win->view->ui) & UI_OPTION_STATUSBAR);
+ lua_pushboolean(L, UI_OPTIONS_GET(win->view.ui) & UI_OPTION_STATUSBAR);
return 1;
} else if (strcmp(key, "tabwidth") == 0 || strcmp(key, "tw") == 0) {
- lua_pushinteger(L, win->view->tabwidth);
+ lua_pushinteger(L, win->view.tabwidth);
return 1;
} else if (strcmp(key, "wrapcolumn") == 0 || strcmp(key, "wc") == 0) {
- lua_pushunsigned(L, win->view->wrapcolumn);
+ lua_pushunsigned(L, win->view.wrapcolumn);
return 1;
}
}
@@ -3492,7 +3492,7 @@ static void vis_lua_win_close(Vis *vis, Win *win) {
obj_ref_new(L, win, VIS_LUA_TYPE_WINDOW);
pcall(vis, L, 1, 0);
}
- obj_ref_free(L, win->view);
+ obj_ref_free(L, &win->view);
obj_ref_free(L, win);
lua_pop(L, 1);
}