Skip to content

Commit

Permalink
feat(cli): Change module load error to suggestion for how to install …
Browse files Browse the repository at this point in the history
…3rd party modules
  • Loading branch information
alerque committed Dec 12, 2023
1 parent 854a0ec commit c280050
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions core/sile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,43 @@ SILE.init = function ()
runEvals(SILE.input.evaluates, "evaluate")
end

local function suggest_luarocks (module)
local guessed_module_name = module:gsub(".*%.", "") .. ".sile"
return ([[
If the expected module is a 3rd party extension you may need to install it
using LuaRocks. The details of how to do this are highly dependent on
your system and preferred installation method, but as an example installing
a 3rd party SILE module to a project-local tree where might look like this:
luarocks --lua-version %s --tree lua_modules install %s
This will install the LuaRocks to your project, then you need to tell your
shell to pass along that info about available LuaRocks paths to SILE. This
only needs to be done once in each shell.
eval $(luarocks --lua-version %s --tree lua_modules path)
Thereafter running SILE again should work as expected:
sile %s
]]):format(
SILE.lua_version,
guessed_module_name,
SILE.lua_version,
pl.stringx.join(" ", _G.arg)
)
end

SILE.use = function (module, options)
local pack
local status, pack
if type(module) == "string" then
pack = require(module)
status, pack = pcall(require, module)
if not status then
SU.error(("Unable to use '%s':\n%s%s")
:format(module, SILE.traceback and (" Lua ".. pack) or "", suggest_luarocks(module)))
end
elseif type(module) == "table" then
pack = module
end
Expand Down

0 comments on commit c280050

Please sign in to comment.