about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-11-25 21:04:08 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-11-25 21:04:08 -0800
commitf930b9e7c734a2141a7afd4cc85fc587ccf8e758 (patch)
treee643486adc4328b3c7e93e092a6367abbc497f63 /src
parent61ea63adca34b34ec8f33253f4895f80e16cb967 (diff)
downloadteliva-f930b9e7c734a2141a7afd4cc85fc587ccf8e758.tar.gz
extract a function
Diffstat (limited to 'src')
-rw-r--r--src/lua.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/lua.c b/src/lua.c
index 04de892..aee975c 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -311,17 +311,8 @@ static const char *look_up_definition (lua_State *L, const char *name) {
 }
 
 
-char *Image_name = NULL;
-static int handle_image (lua_State *L, char **argv, int n) {
+int resume_loading_definitions(lua_State *L) {
   int status;
-  int narg = getargs(L, argv, n);  /* collect arguments */
-  lua_setglobal(L, "arg");
-  /* parse and load file contents (teliva_program array) */
-  Image_name = argv[n];
-  status = luaL_loadfile(L, Image_name);
-  lua_insert(L, -(narg+1));
-  if (status != 0) return status;
-  status = docall(L, narg, 0);
   lua_getglobal(L, "teliva_program");
   int history_array = lua_gettop(L);
   /* iterate over mutations in teliva_program history in reverse order */
@@ -342,6 +333,23 @@ static int handle_image (lua_State *L, char **argv, int n) {
     lua_pop(L, 1);
   }
   lua_pop(L, 1);
+  return 0;
+}
+
+
+char *Image_name = NULL;
+static int handle_image (lua_State *L, char **argv, int n) {
+  int status;
+  int narg = getargs(L, argv, n);  /* collect arguments */
+  lua_setglobal(L, "arg");
+  /* parse and load file contents (teliva_program array) */
+  Image_name = argv[n];
+  status = luaL_loadfile(L, Image_name);
+  lua_insert(L, -(narg+1));
+  if (status != 0) return status;
+  status = docall(L, narg, 0);
+  status = resume_loading_definitions(L);
+  if (status != 0) return 0;
   /* call main() */
   lua_getglobal(L, "main");
   status = docall(L, 0, 1);