about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-11-28 15:19:26 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-11-28 15:19:26 -0800
commit2f42187663425d994660876ca76cacd69c085bbc (patch)
tree5b960ce0708392c7fb5758791073b03178b8bef1 /src
parent37068ef8d2a768566738feaaf23e76478ae82e38 (diff)
downloadteliva-2f42187663425d994660876ca76cacd69c085bbc.tar.gz
fix the bug described in commit cec57992b7
Diffstat (limited to 'src')
-rw-r--r--src/lua.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/lua.c b/src/lua.c
index 22206f1..0a5b608 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -433,10 +433,8 @@ static void read_editor_buffer (char *out) {
 
 
 static void update_definition (lua_State *L, const char *name, char *new_contents) {
-  assert(lua_gettop(L) == 0);
   lua_getglobal(L, "teliva_program");
   int history_array = lua_gettop(L);
-  assert(history_array == 1);
   /* create a new table containing a single binding */
   lua_createtable(L, /*number of fields per mutation*/2, 0);
   lua_pushstring(L, new_contents);
@@ -452,7 +450,7 @@ static void update_definition (lua_State *L, const char *name, char *new_content
   int history_array_size = luaL_getn(L, history_array);
   ++history_array_size;
   lua_rawseti(L, history_array, history_array_size);
-  lua_settop(L, 0);
+  lua_settop(L, history_array);
 }
 
 
@@ -943,7 +941,17 @@ int restore_editor_view (lua_State *L) {
   int cx = lua_tointeger(L, -1);
   lua_settop(L, editor_state_index);
   int back_to_big_picture = edit_from(L, "teliva_editor_buffer", /*error message*/ "", rowoff, coloff, cy, cx);
-  // TODO: error handling like in edit_current_definition
+  // error handling
+  while (1) {
+    int status;
+    status = load_editor_buffer_to_current_definition_in_image(L);
+    if (status == 0 || lua_isnil(L, -1))
+      break;
+    Previous_error = lua_tostring(L, -1);
+    if (Previous_error == NULL) Previous_error = "(error object is not a string)";
+    back_to_big_picture = resumeEdit(L);
+    lua_pop(L, 1);
+  }
   return back_to_big_picture;
 }
 
='#n46'>46 47 48 49 50 51 52 53 54
55
56
57
58
59
60