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-11 15:30:33 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-12-11 15:30:33 -0800
commitf315e1d76ab63993ad052be3e9364a2286b59d8c (patch)
treef8feb05cf33e5dee5043b3cef3b0f30db766acdc /src/lua.c
parentb9877fabdc371efa2759b1d628d9fc65d96bcbd8 (diff)
downloadteliva-f315e1d76ab63993ad052be3e9364a2286b59d8c.tar.gz
can again edit notes on changes
Diffstat (limited to 'src/lua.c')
-rw-r--r--src/lua.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/lua.c b/src/lua.c
index 5ee8481..4171856 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -582,8 +582,8 @@ void add_undo_event(lua_State *L, int cursor) {
 }
 
 
-/* precondition: teliva_program is at top of stack */
 void save_note_to_editor_buffer (lua_State *L, int cursor) {
+  lua_getglobal(L, "teliva_program");
   lua_rawgeti(L, -1, cursor);
   lua_getfield(L, -1, "__teliva_note");
   const char *contents = lua_tostring(L, -1);
@@ -591,18 +591,18 @@ void save_note_to_editor_buffer (lua_State *L, int cursor) {
   if (contents != NULL)
     fprintf(out, "%s", contents);
   fclose(out);
-  lua_pop(L, 2);  /* contents, table at cursor */
+  lua_pop(L, 3);  /* contents, table at cursor, teliva_program */
 }
 
 
-/* precondition: teliva_program is at top of stack */
 void load_note_from_editor_buffer (lua_State *L, int cursor) {
+  lua_getglobal(L, "teliva_program");
   char new_contents[8192] = {0};
   read_editor_buffer(new_contents);
   lua_rawgeti(L, -1, cursor);
   lua_pushstring(L, new_contents);
   lua_setfield(L, -2, "__teliva_note");
-  lua_pop(L, 1);  /* table at cursor */
+  lua_pop(L, 2);  /* table at cursor, teliva_program */
 }