aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-02-17 21:50:10 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-02-18 16:50:40 +0100
commita04408c5918376be63a1902fd71726dfff9edb3e (patch)
tree32820f09792969a1889778ee395719d1b914def4
parent498723377cbf5cdb36d8b64f41b219a515a84175 (diff)
downloadvis-a04408c5918376be63a1902fd71726dfff9edb3e.tar.gz
vis-a04408c5918376be63a1902fd71726dfff9edb3e.tar.xz
vis-lua: expose vis:textobject_register
-rw-r--r--vis-lua.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/vis-lua.c b/vis-lua.c
index 3f3c4a3..0ea7d48 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -404,6 +404,29 @@ static int textobject(lua_State *L) {
return 1;
}
+
+static Filerange textobject_lua(Vis *vis, Win *win, void *data, size_t pos) {
+ lua_State *L = vis->lua;
+ if (!func_ref_get(L, data) || !obj_ref_new(L, win, "vis.window"))
+ return text_range_empty();
+ lua_pushunsigned(L, pos);
+ if (pcall(vis, L, 2, 2) != 0)
+ return text_range_empty();
+ return text_range_new(luaL_checkunsigned(L, -2), luaL_checkunsigned(L, -1));
+}
+
+static int textobject_register(lua_State *L) {
+ int id = -1;
+ const void *func;
+ Vis *vis = obj_ref_check(L, 1, "vis");
+ if (!vis || !lua_isfunction(L, 2) || !(func = func_ref_new(L)))
+ goto err;
+ id = vis_textobject_register(vis, 0, (void*)func, textobject_lua);
+err:
+ lua_pushinteger(L, id);
+ return 1;
+}
+
static int vis_index(lua_State *L) {
Vis *vis = obj_ref_check(L, 1, "vis");
if (!vis) {
@@ -469,6 +492,7 @@ static const struct luaL_Reg vis_lua[] = {
{ "motion", motion },
{ "motion_register", motion_register },
{ "textobject", textobject },
+ { "textobject_register", textobject_register },
{ "__index", vis_index },
{ "__newindex", vis_newindex },
{ NULL, NULL },