fix(require/loadJson): correct path for json files

This commit is contained in:
Linden
2024-04-09 20:02:35 +10:00
parent 10ee931877
commit fffdcd9999

View File

@@ -121,7 +121,7 @@ function lib.load(filePath, env)
if result then return result() end if result then return result() end
error(err) error(("file '%s' not found\n\t%s"):format(filePath, err))
end end
---@param filePath string ---@param filePath string
@@ -132,14 +132,14 @@ function lib.loadJson(filePath)
error(("file path must be a string (received '%s')"):format(filePath), 2) error(("file path must be a string (received '%s')"):format(filePath), 2)
end end
local resourceSrc, modPath = getModuleInfo(filePath) local resourceSrc, modPath = getModuleInfo(filePath:gsub('%.', '/'))
local resourceFile = LoadResourceFile(resourceSrc, ('%s.json'):format(modPath)) local resourceFile = LoadResourceFile(resourceSrc, ('%s.json'):format(modPath))
if resourceFile then if resourceFile then
return json.decode(resourceFile) return json.decode(resourceFile)
end end
error(('cannot load json file at path %s'):format(modPath)) error(("json file '%s' not found\n\tno file '@%s/%s.json'"):format(filePath, resourceSrc, modPath))
end end
---Loads the given module, returns any value returned by the seacher (`true` when `nil`).\ ---Loads the given module, returns any value returned by the seacher (`true` when `nil`).\