diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2020-09-17 14:28:40 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2020-09-17 15:30:27 +0200 |
| commit | bacc6e08a6297ecee09ba81f6fa0265b86c78adc (patch) | |
| tree | b647df637dc83b4d7df7d14bb146485ef50e2a60 | |
| parent | 080875a056e76a4279e51687a6fc36d81835e243 (diff) | |
| download | vis-bacc6e08a6297ecee09ba81f6fa0265b86c78adc.tar.gz vis-bacc6e08a6297ecee09ba81f6fa0265b86c78adc.tar.xz | |
vis-lua: use utility function to translate register names
| -rw-r--r-- | vis-lua.c | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -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; } |
