about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-11-13 17:48:04 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-11-13 17:48:04 -0800
commit625a66e1961610742f5eb698fa9dd84454958b2e (patch)
tree942d4376226d0fee77d284f1d0b5969c49c3d2c6
parent12b2a44cf6413ef0c51c4e13af1c03369f9e803f (diff)
downloadteliva-625a66e1961610742f5eb698fa9dd84454958b2e.tar.gz
avoid side-effects on the Lua stack
-rw-r--r--src/lua.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/lua.c b/src/lua.c
index f226828..327cadd 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -316,6 +316,7 @@ void save_to_current_definition_and_editor_buffer (lua_State *L, const char *def
     if (contents != NULL)
       write(outfd, contents, strlen(contents));
     close(outfd);
+    lua_settop(L, 0);
 }
 
 
@@ -328,13 +329,16 @@ static void read_contents (lua_State *L, char *filename, char *out) {
 
 /* table to update is at top of stack */
 static void update_definition (lua_State *L, const char *name, char *out) {
+    lua_getglobal(L, "teliva_program");
     lua_pushstring(L, out);
     assert(strlen(name) > 0);
     lua_setfield(L, -2, name);
+    lua_settop(L, 0);
 }
 
 
 static void save_image (lua_State *L) {
+    lua_getglobal(L, "teliva_program");
     int table = lua_gettop(L);
     FILE* fp = fopen(Image_name, "w");
     fprintf(fp, "teliva_program = {\n");
@@ -347,6 +351,7 @@ static void save_image (lua_State *L) {
     }
     fprintf(fp, "}\n");
     fclose(fp);
+    lua_settop(L, 0);
 }
 
 
m> 2018-11-26 00:37:10 -0500 Upload files to ''' href='/tilde/site/commit/signup.html?id=acb2558525a01cd9e9ed527c38eef646709c8612'>acb2558 ^
966b37d ^
acb2558 ^
a2ddf49 ^
29d7dcd ^
acb2558 ^

966b37d ^
acb2558 ^





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39