about summary refs log tree commit diff stats
path: root/src/lua.c
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-11-13 08:16:41 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-11-13 08:16:41 -0800
commit5a44605143362c8d240c20c849593a3739bf9bed (patch)
treea2a866314c30ce299ed90a3ed31ebe526ea286d8 /src/lua.c
parent0f4faf0e5333542040a809e3b97d05426b69d40d (diff)
downloadteliva-5a44605143362c8d240c20c849593a3739bf9bed.tar.gz
instrumenting function calls with their depth
Diffstat (limited to 'src/lua.c')
-rw-r--r--src/lua.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/lua.c b/src/lua.c
index 08c5f92..59c50ca 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -370,6 +370,16 @@ void switch_to_editor (lua_State *L, const char *message) {
   if (Script_name)
     edit(L, Script_name, message);
   else {
+    luaL_newmetatable(L, "__teliva_call_graph_depth");
+    int cgt = lua_gettop(L);
+    printf("cgt: %d\n", cgt);
+    for (lua_pushnil(L); lua_next(L, cgt) != 0;) {
+      const char* function_name = lua_tostring(L, -2);
+      int depth = lua_tointeger(L, -1);
+      printf("%s: %d\n", function_name, depth);
+      lua_pop(L, 1);  // pop value, leave key on stack for next iteration
+    }
+    exit(4);
     Current_definition = "main";
     write_definition_to_file(L, Current_definition, "teliva_editbuffer");
     edit(L, "teliva_editbuffer", /*status message*/ "");