diff options
Diffstat (limited to 'src/lua.c')
-rw-r--r-- | src/lua.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/lua.c b/src/lua.c index e75ba92..9b7cd76 100644 --- a/src/lua.c +++ b/src/lua.c @@ -309,6 +309,15 @@ static int handle_image (lua_State *L, char **argv, int n) { } +int definition_exists (lua_State *L, char *name) { + lua_getglobal(L, "teliva_program"); + lua_getfield(L, -1, name); + const char *contents = lua_tostring(L, -1); + lua_pop(L, 1); + return contents != NULL; +} + + void write_definition_to_file (lua_State *L, char *name, char *outfilename) { lua_getglobal(L, "teliva_program"); lua_getfield(L, -1, name); @@ -368,9 +377,8 @@ void switch_to_editor (lua_State *L, const char *message) { read_contents(L, "teliva_editbuffer", new_contents); update_definition(L, Current_definition, new_contents); save_image(L); - /* reload binding */ + /* reload binding if possible */ dostring(L, new_contents, Current_definition); - /* TODO: handle error */ } execv(Argv[0], Argv); /* never returns */ |