From bacc6e08a6297ecee09ba81f6fa0265b86c78adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Thu, 17 Sep 2020 14:28:40 +0200 Subject: vis-lua: use utility function to translate register names --- vis-lua.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'vis-lua.c') diff --git a/vis-lua.c b/vis-lua.c index 8028fed..fc2e5c2 100644 --- a/vis-lua.c +++ b/vis-lua.c @@ -719,22 +719,20 @@ static int mark_names_iter(lua_State *L) { */ static int register_names_iter(lua_State *L); static int register_names(lua_State *L) { + Vis *vis = obj_ref_check(L, 1, "vis"); + lua_pushlightuserdata(L, vis); enum VisRegister *handle = lua_newuserdata(L, sizeof *handle); *handle = 0; - lua_pushcclosure(L, register_names_iter, 1); + lua_pushcclosure(L, register_names_iter, 2); return 1; } static int register_names_iter(lua_State *L) { - char reg = '\0'; - enum VisRegister *handle = lua_touserdata(L, lua_upvalueindex(1)); - if (*handle < LENGTH(vis_registers)) - reg = vis_registers[*handle].name; - else if (VIS_REG_a <= *handle && *handle <= VIS_REG_z) - reg = 'a' + *handle - VIS_REG_a; + Vis *vis = lua_touserdata(L, lua_upvalueindex(1)); + enum VisRegister *handle = lua_touserdata(L, lua_upvalueindex(2)); + char reg = vis_register_to(vis, *handle); if (reg) { - char name[2] = { reg, '\0' }; - lua_pushstring(L, name); + lua_pushlstring(L, ®, 1); (*handle)++; return 1; } -- cgit v1.2.3