diff options
Diffstat (limited to 'src/lua.c')
-rw-r--r-- | src/lua.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/lua.c b/src/lua.c index 88052d0..500f64d 100644 --- a/src/lua.c +++ b/src/lua.c @@ -378,19 +378,41 @@ void load_editor_buffer_to_current_definition_in_image(lua_State *L) { } -void editImage (lua_State *L) { - save_to_current_definition_and_editor_buffer(L, "main"); +void editImage (lua_State *L, const char *definition) { + save_to_current_definition_and_editor_buffer(L, definition); editBuffer(L, /*status message*/ ""); load_editor_buffer_to_current_definition_in_image(L); } +void browseImage (lua_State *L) { + clear(); + luaL_newmetatable(L, "__teliva_call_graph_depth"); + int cgt = lua_gettop(L); + int y = 2; + for (lua_pushnil(L); lua_next(L, cgt) != 0;) { + const char* function_name = lua_tostring(L, -2); + int depth = lua_tointeger(L, -1); + mvprintw(y, 0, "%s: %d", function_name, depth); + ++y; + lua_pop(L, 1); // pop value, leave key on stack for next iteration + } + int maxy, maxx; + getmaxyx(stdscr, maxy, maxx); + (void)maxx; // unused + mvaddstr(maxy-1, 0, "edit what? "); + char definition[64] = {0}; + getnstr(definition, 60); + editImage(L, definition); +} + + void switch_to_editor (lua_State *L, const char *message) { endwin(); if (Script_name) edit(L, Script_name, message); else - editImage(L); + browseImage(L); execv(Argv[0], Argv); /* never returns */ } |