Skip to content

Commit 9439b70

Browse files
committed
Merge branch 'master' of https://github.com/Pyroxenium/Obsidian
2 parents 79e13e2 + c19143a commit 9439b70

3 files changed

Lines changed: 49 additions & 31 deletions

File tree

‎bundle/obsidian.compressed.lua‎

Lines changed: 5 additions & 3 deletions
Large diffs are not rendered by default.

‎bundle/obsidian.lua‎

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3980,17 +3980,20 @@ local loader = {
39803980
}
39813981
loader.flimg = flimg
39823982
local function resolvePath(path)
3983-
if not path or path:sub(1,1) == "/" then return path end
3983+
if not path then return path, "no path" end
3984+
if path:sub(1, 1) == "/" then return path, "absolute path" end
39843985
if loader.basePath then
3985-
return fs.combine(loader.basePath, path)
3986+
return fs.combine(loader.basePath, path),
3987+
"basePath '" .. tostring(loader.basePath) .. "'"
39863988
end
3987-
if shell then
3989+
if shell and shell.getRunningProgram then
39883990
local runningProg = shell.getRunningProgram()
3989-
if runningProg then
3990-
return fs.combine(fs.getDir(runningProg), path)
3991+
if runningProg and runningProg ~= "" then
3992+
return fs.combine(fs.getDir(runningProg), path),
3993+
"directory of " .. runningProg
39913994
end
39923995
end
3993-
return path
3996+
return path, "unchanged (no basePath, and no shell to resolve against)"
39943997
end
39953998
function loader.setBasePath(path)
39963999
loader.basePath = path
@@ -4001,9 +4004,10 @@ local function toTable(str)
40014004
return t
40024005
end
40034006
local function _loadFile(path)
4004-
local fullPath = resolvePath(path)
4007+
local fullPath, origin = resolvePath(path)
40054008
if not fs.exists(fullPath) then
4006-
return false, "File not found: " .. fullPath
4009+
return false, ("File not found: %s (resolved from '%s' via %s)")
4010+
:format(fullPath, tostring(path), origin)
40074011
end
40084012
local file = fs.open(fullPath, "r")
40094013
if not file then
@@ -4107,9 +4111,12 @@ function loader.loadSprite(path)
41074111
return data
41084112
end
41094113
function loader.loadImage(path)
4110-
local fullPath = resolvePath(path)
4114+
local fullPath, origin = resolvePath(path)
41114115
if loader.imageCache[fullPath] then return loader.imageCache[fullPath] end
4112-
if not fs.exists(fullPath) then return nil, "File not found: " .. fullPath end
4116+
if not fs.exists(fullPath) then
4117+
return nil, ("File not found: %s (resolved from '%s' via %s)")
4118+
:format(fullPath, tostring(path), origin)
4119+
end
41134120
local handle = fs.open(fullPath, "rb") or fs.open(fullPath, "r")
41144121
if not handle then return nil, "Could not open file: " .. fullPath end
41154122
local raw = handle.readAll()
@@ -8520,8 +8527,10 @@ local function loader(name)
85208527
end
85218528
local source = sources[name]
85228529
or error("Obsidian: module not bundled: " .. tostring(name), 0)
8530+
-- Same contract as src/init.lua: modules run in the caller's environment,
8531+
-- so CraftOS-provided globals such as shell stay visible to them.
85238532
local chunk = assert(load(source,
8524-
"@obsidian/" .. (paths[name] or name) .. ".lua"))
8533+
"@obsidian/" .. (paths[name] or name) .. ".lua", nil, _ENV))
85258534
loading[name] = true
85268535
local result = chunk(loader, name)
85278536
loading[name] = nil

‎bundle/obsidian.min.lua‎

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,18 +1513,22 @@ paths["core.input_mapper"] = "core/input_mapper"
15131513
sources["core.loader"] = [=[
15141514
local ca=...local da=ca("core.logger")local _b=ca("flimg")
15151515
local ab={basePath=nil,spriteCache={},imageCache={},uiCache={},emitterCache={}}ab.flimg=_b
1516-
local function bb(_c)
1517-
if not _c or _c:sub(1,1)=="/"then return _c end
1518-
if ab.basePath then return fs.combine(ab.basePath,_c)end
1519-
if shell then local ac=shell.getRunningProgram()if ac then return
1520-
fs.combine(fs.getDir(ac),_c)end end;return _c end;function ab.setBasePath(_c)ab.basePath=_c end;local function cb(_c)local ac={}for i=1,#_c do
1516+
local function bb(_c)if not _c then return _c,"no path"end;if _c:sub(1,1)=="/"then return _c,
1517+
"absolute path"end;if ab.basePath then
1518+
return fs.combine(ab.basePath,_c),
1519+
"basePath '"..tostring(ab.basePath).."'"end
1520+
if
1521+
shell and shell.getRunningProgram then local ac=shell.getRunningProgram()
1522+
if ac and ac~=""then return
1523+
fs.combine(fs.getDir(ac),_c),"directory of "..ac end end;return _c,"unchanged (no basePath, and no shell to resolve against)"end;function ab.setBasePath(_c)ab.basePath=_c end;local function cb(_c)local ac={}for i=1,#_c do
15211524
ac[i]=_c:sub(i,i)end;return ac end
15221525
local function db(_c)
1523-
local ac=bb(_c)
1524-
if not fs.exists(ac)then return false,"File not found: "..ac end;local bc=fs.open(ac,"r")if not bc then
1525-
return false,"Could not open file: "..ac end;local cc=bc.readAll()bc.close()
1526-
local dc,_d=pcall(textutils.unserialize,cc)
1527-
if not dc or _d==nil then return false,"Failed to unserialize: "..ac end;return true,_d,ac end
1526+
local ac,bc=bb(_c)
1527+
if not fs.exists(ac)then return false,
1528+
("File not found: %s (resolved from '%s' via %s)"):format(ac,tostring(_c),bc)end;local cc=fs.open(ac,"r")if not cc then
1529+
return false,"Could not open file: "..ac end;local dc=cc.readAll()cc.close()
1530+
local _d,ad=pcall(textutils.unserialize,dc)
1531+
if not _d or ad==nil then return false,"Failed to unserialize: "..ac end;return true,ad,ac end
15281532
function ab._processSprite(_c)if not _c then return end
15291533
for i=1,(_c.frameCount or#_c)do local ac=_c[i]if ac then
15301534
for layer=1,3 do if ac[layer]then
@@ -1563,14 +1567,15 @@ da.error("Loader: Validation error in "..
15631567
_c..": "..ad)return nil,ad end
15641568
ab._processSprite(cc)cc.path=_c;ab.spriteCache[dc]=cc
15651569
da.info("Loader: Cached sprite: "..dc)return cc end
1566-
function ab.loadImage(_c)local ac=bb(_c)
1570+
function ab.loadImage(_c)local ac,bc=bb(_c)
15671571
if ab.imageCache[ac]then return ab.imageCache[ac]end
1568-
if not fs.exists(ac)then return nil,"File not found: "..ac end;local bc=fs.open(ac,"rb")or fs.open(ac,"r")if not bc then return nil,
1572+
if not fs.exists(ac)then return nil,
1573+
("File not found: %s (resolved from '%s' via %s)"):format(ac,tostring(_c),bc)end;local cc=fs.open(ac,"rb")or fs.open(ac,"r")if not cc then return nil,
15691574
"Could not open file: "..ac end
1570-
local cc=bc.readAll()bc.close()local dc,_d=pcall(_b.decode,cc)if not dc then
1571-
da.error("Loader: "..tostring(_d))return nil,tostring(_d)end;_d.path=_c
1572-
ab.imageCache[ac]=_d
1573-
da.info("Loader: Cached FLIMG image: "..ac)return _d end
1575+
local dc=cc.readAll()cc.close()local _d,ad=pcall(_b.decode,dc)if not _d then
1576+
da.error("Loader: "..tostring(ad))return nil,tostring(ad)end;ad.path=_c
1577+
ab.imageCache[ac]=ad
1578+
da.info("Loader: Cached FLIMG image: "..ac)return ad end
15741579
function ab.loadUI(_c)local ac=bb(_c)
15751580
if ab.uiCache[ac]then return ab.uiCache[ac]end;local bc,cc,dc=db(_c)
15761581
if not bc then da.error("Loader: "..cc)return nil,cc end;ab.uiCache[dc]=cc;return cc end
@@ -3302,8 +3307,10 @@ local function loader(name)
33023307
end
33033308
local source = sources[name]
33043309
or error("Obsidian: module not bundled: " .. tostring(name), 0)
3310+
-- Same contract as src/init.lua: modules run in the caller's environment,
3311+
-- so CraftOS-provided globals such as shell stay visible to them.
33053312
local chunk = assert(load(source,
3306-
"@obsidian/" .. (paths[name] or name) .. ".lua"))
3313+
"@obsidian/" .. (paths[name] or name) .. ".lua", nil, _ENV))
33073314
loading[name] = true
33083315
local result = chunk(loader, name)
33093316
loading[name] = nil

0 commit comments

Comments
 (0)