From d43662b2dcebadf1a16a70584081fd9ad872571f Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sun, 22 Mar 2026 16:07:33 -0400 Subject: [PATCH] Refactor module loading to use dynamic base directory path --- inventoryManager.lua | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/inventoryManager.lua b/inventoryManager.lua index f1ca738..3c1e3f2 100644 --- a/inventoryManager.lua +++ b/inventoryManager.lua @@ -8,19 +8,26 @@ -- manager/display.lua — dashboard rendering & touch handlers -- inventoryManager.lua — this file: orchestrator, main(), network handler +------------------------------------------------- +-- Resolve base directory for portable path resolution +------------------------------------------------- + +local _baseDir = fs.getDir(shell.getRunningProgram()) +local function _path(rel) return fs.combine(_baseDir, rel) end + ------------------------------------------------- -- Structured logging & shared UI helpers ------------------------------------------------- -local log = dofile("lib/log.lua") -local ui = dofile("lib/ui.lua") +local log = dofile(_path("lib/log.lua")) +local ui = dofile(_path("lib/ui.lua")) ------------------------------------------------- -- Load modules (factory pattern → shared context) ------------------------------------------------- -local cfg = dofile("manager/config.lua")(log) -local state = dofile("manager/state.lua")() +local cfg = dofile(_path("manager/config.lua"))(log, _path) +local state = dofile(_path("manager/state.lua"))() -- Shared context table (Lua tables are by-reference, so all -- modules see the same mutable cache/activity/etc) @@ -35,10 +42,10 @@ local ctx = { craftTurtleName = nil, } -local ops = dofile("manager/operations.lua")(ctx) +local ops = dofile(_path("manager/operations.lua"))(ctx) ctx.ops = ops -local display = dofile("manager/display.lua")(ctx) +local display = dofile(_path("manager/display.lua"))(ctx) ctx.display = display -- Convenience aliases