Bundle error: Unknown source (Access is denied)

So you’re requiring files that you have in custom resources? The require() function will only look for files inside the application bundle and the bundling process will only include .lua files that are required by other files that are included in the main application bundle (based on the resource tree generated from the bootstrap collection).

If you want to load and run Lua code from custom resources you need to do something like this:

-- load the lua file as a string
local s = sys.load_resource("/foo/bar.lua")

-- compile the lua code in bar.lua and run it once, storing it's result in bar
local bar = loadstring(s)()

This is not really the same as require() since bar.lua will not be loaded into package.loaded. Maybe a better solution would be to add a new loader function?

local function custom_resources_loader(s)
	-- we may need to modify s here, replacing . with /
	local s = sys.load_resource(s)
	if not s then
		return nil
	end
	return loadstring(s)()
end

table.insert(package.loaders(), custom_resources_loader)

I’m a bit pressed for time here so I can’t investigate further right now…

2 Likes