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 15:07:14 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-11-13 15:07:14 -0800
commitcbd5e7d5529027e7440bafa7e3ee6412bae3531d (patch)
treee944cf1bf7a985bdb184c9ec4409d24dd49b8719 /src/lua.c
parente06a7b1a7b7f1748ca6bb22a53c91c9ab288a3d5 (diff)
downloadteliva-cbd5e7d5529027e7440bafa7e3ee6412bae3531d.tar.gz
.
Diffstat (limited to 'src/lua.c')
-rw-r--r--src/lua.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/lua.c b/src/lua.c
index 304dada..0122eac 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -318,12 +318,14 @@ static int definition_exists (lua_State *L, char *name) {
 }
 
 
-void write_definition_to_file (lua_State *L, char *name, char *outfilename) {
+char *Current_definition = NULL;
+void save_to_current_definition_and_editor_buffer (lua_State *L, char *definition) {
+    Current_definition = definition;
     lua_getglobal(L, "teliva_program");
-    lua_getfield(L, -1, name);
+    lua_getfield(L, -1, Current_definition);
     const char *contents = lua_tostring(L, -1);
     lua_pop(L, 1);
-    int outfd = open(outfilename, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+    int outfd = open("teliva_editbuffer", O_WRONLY|O_CREAT|O_TRUNC, 0644);
     if (contents != NULL)
       write(outfd, contents, strlen(contents));
     close(outfd);
@@ -363,7 +365,6 @@ static void save_image (lua_State *L) {
 /* death and rebirth */
 char *Script_name = NULL;
 char **Argv = NULL;
-char *Current_definition = NULL;
 extern void edit(lua_State *L, char *filename, const char *status);
 
 
@@ -382,8 +383,7 @@ void switch_to_editor (lua_State *L, const char *message) {
   if (Script_name)
     edit(L, Script_name, message);
   else {
-    Current_definition = "main";
-    write_definition_to_file(L, Current_definition, "teliva_editbuffer");
+    save_to_current_definition_and_editor_buffer(L, "main");
     edit(L, "teliva_editbuffer", /*status message*/ "");
     load_editor_buffer_to_current_definition_in_image(L);
   }