From cbd5e7d5529027e7440bafa7e3ee6412bae3531d Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 13 Nov 2021 15:07:14 -0800 Subject: . --- src/lua.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/lua.c') 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); } -- cgit 1.4.1-2-gfad0