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-12-17 21:32:32 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-12-17 21:32:32 -0800
commit3921337b3fa1b6413206829c1a3e2e8836c153a9 (patch)
tree409fc826b027d0c7f158e042c1646901bb6280e8 /src/lua.c
parenta617b3e5ac9e47d7a374a02ab091f050dc0bd556 (diff)
downloadteliva-3921337b3fa1b6413206829c1a3e2e8836c153a9.tar.gz
yet another stab at reorganizing stack assertions
Diffstat (limited to 'src/lua.c')
-rw-r--r--src/lua.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/lua.c b/src/lua.c
index 02f660b..a0c763f 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -424,20 +424,13 @@ static void update_definition (lua_State *L, const char *name, char *new_content
 
 extern void save_tlv (lua_State *L, char *filename);
 int load_editor_buffer_to_current_definition_in_image(lua_State *L) {
-  int oldtop = lua_gettop(L);
   char new_contents[8192] = {0};
   read_editor_buffer(new_contents, 8190);
   update_definition(L, Current_definition, new_contents);
   save_tlv(L, Image_name);
   /* reload binding */
-  int status = luaL_loadbuffer(L, new_contents, strlen(new_contents), Current_definition);
-  if (status == 0) status = docall(L, 0, 1);
-  if (lua_gettop(L) != oldtop) {
-    endwin();
-    printf("load_editor_buffer_to_current_definition_in_image: memory leak %d -> %d\n", oldtop, lua_gettop(L));
-    exit(1);
-  }
-  return status;
+  return luaL_loadbuffer(L, new_contents, strlen(new_contents), Current_definition)
+      || docall(L, 0, 1);
 }
 
 
@@ -448,6 +441,7 @@ extern int resumeEdit (lua_State *L);
 int edit_current_definition (lua_State *L) {
   int back_to_big_picture = edit(L, "teliva_editor_buffer");
   // error handling
+  int oldtop = lua_gettop(L);
   while (1) {
     int status;
     status = load_editor_buffer_to_current_definition_in_image(L);
@@ -458,6 +452,11 @@ int edit_current_definition (lua_State *L) {
     back_to_big_picture = resumeEdit(L);
     lua_pop(L, 1);
   }
+  if (lua_gettop(L) != oldtop) {
+    endwin();
+    printf("edit_current_definition: memory leak %d -> %d\n", oldtop, lua_gettop(L));
+    exit(1);
+  }
   return back_to_big_picture;
 }
 
@@ -947,6 +946,7 @@ int restore_editor_view (lua_State *L) {
   lua_settop(L, editor_state_index);
   int back_to_big_picture = edit_from(L, "teliva_editor_buffer", rowoff, coloff, cy, cx);
   // error handling
+  int oldtop = lua_gettop(L);
   while (1) {
     int status;
     status = load_editor_buffer_to_current_definition_in_image(L);
@@ -957,6 +957,11 @@ int restore_editor_view (lua_State *L) {
     back_to_big_picture = resumeEdit(L);
     lua_pop(L, 1);
   }
+  if (lua_gettop(L) != oldtop) {
+    endwin();
+    printf("edit_from: memory leak %d -> %d\n", oldtop, lua_gettop(L));
+    exit(1);
+  }
   return back_to_big_picture;
 }