aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-03-07 16:01:19 -0800
committerKartik K. Agaram <vc@akkartik.com>2022-03-07 16:01:19 -0800
commit88827db20d7a2d1acde328f0b77351475d516d4a (patch)
tree0896218ea32d5f464a4bb4cee5e0b1b37ec3522e
parentb1ad679f3b7d55c150d6e6fdf101038ef4e7a5d7 (diff)
downloadteliva-88827db20d7a2d1acde328f0b77351475d516d4a.tar.gz
slightly firm up phases in pmain
-rw-r--r--src/lua.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/lua.c b/src/lua.c
index 263d89c..82b995c 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -212,8 +212,9 @@ static int pmain (lua_State *L) {
int status;
globalL = L;
if (argv[0] && argv[0][0]) progname = argv[0];
- lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
+
/* Libraries that can be over-ridden */
+ lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
luaL_openlibs(L);
status = dorequire(L, "src/lcurses/curses.lua", "curses");
if (status != 0) return 0;
@@ -240,17 +241,23 @@ static int pmain (lua_State *L) {
status = dorequire(L, "src/task.lua", "task");
if (status != 0) return 0;
lua_gc(L, LUA_GCRESTART, 0);
+
s->status = handle_luainit(L);
if (s->status != 0) return 0;
s->status = load_image(L, argv, 1);
if (s->status != 0) return 0;
+
/* Security-sensitive libraries that cannot be over-ridden */
- status = dorequire(L, "src/file.lua", "file");
+ /* As a rule of thumb, if we ever special-case any Lua function names in C
+ * code, that's a signal it needs to load after the app. */
+ status = dorequire(L, "src/file.lua", "file"); /* special-cased in io_open */
if (status != 0) return 0;
+
/* call main() */
lua_getglobal(L, "spawn_main");
s->status = docall(L, 0, 1);
if (s->status != 0) return report_in_developer_mode(L, s->status);
+
return 0;
}