about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/kilo.c6
-rw-r--r--src/lua.c12
2 files changed, 8 insertions, 10 deletions
diff --git a/src/kilo.c b/src/kilo.c
index f0a815c..3183639 100644
--- a/src/kilo.c
+++ b/src/kilo.c
@@ -1169,8 +1169,7 @@ static void editorMoveCursor(int key) {
     }
 }
 
-extern char* Current_definition;
-extern void write_definition_to_file(lua_State *L, char *name, char *outfilename);
+extern void save_to_current_definition_and_editor_buffer(lua_State *L, char *name);
 extern void load_editor_buffer_to_current_definition_in_image(lua_State *L);
 static void editorGo(lua_State* L, int fd) {
     char query[KILO_QUERY_LEN+1] = {0};
@@ -1189,8 +1188,7 @@ static void editorGo(lua_State* L, int fd) {
         } else if (c == ESC || c == ENTER) {
             editorSetStatusMessage("");
             if (c == ENTER) {
-              Current_definition = query;
-              write_definition_to_file(L, Current_definition, "teliva_editbuffer");
+              save_to_current_definition_and_editor_buffer(L, query);
               editorClear();
               editorOpen("teliva_editbuffer");
             }
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);
   }