From 064b6d0b9551e483e02f1347dac0aa8a6225a8c8 Mon Sep 17 00:00:00 2001 From: rxi Date: Tue, 26 May 2020 10:17:36 +0100 Subject: [PATCH] Fixed changing of cwd and loading of commandline files the current-working-directory is now set at the start of `core.init` after the absolute path for all filename arguments have been resolved --- data/core/init.lua | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 0836440..ce17716 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -82,6 +82,19 @@ function core.init() CommandView = require "core.commandview" Doc = require "core.doc" + local project_dir = "." + local files = {} + for i = 2, #ARGS do + local info = system.get_file_info(ARGS[i]) or {} + if info.type == "file" then + table.insert(files, system.absolute_path(ARGS[i])) + elseif info.type == "dir" then + project_dir = ARGS[i] + end + end + + system.chdir(project_dir) + core.frame_start = 0 core.clip_rect_stack = {{ 0,0,0,0 }} core.log_items = {} @@ -103,20 +116,13 @@ function core.init() local got_user_error = not core.try(require, "user") local got_project_error = not core.load_project_module() - for i = 2, #ARGS do - local filename = ARGS[i] - local info = system.get_file_info(filename) - if info and info.type == "file" then - core.root_view:open_doc(core.open_doc(filename)) - end + for _, filename in ipairs(files) do + core.root_view:open_doc(core.open_doc(filename)) end if got_plugin_error or got_user_error or got_project_error then command.perform("core:open-log") end - - local info = ARGS[2] and system.get_file_info(ARGS[2]) - system.chdir(info and info.type == "dir" and ARGS[2] or ".") end