1use eyre::{OptionExt, Result};
2use lux_lib::{
3 config::{Config, LuaVersion},
4 lua_installation::LuaInstallation,
5 progress::{MultiProgress, ProgressBar},
6};
7
8pub async fn install_lua(config: Config) -> Result<()> {
9 let version_stringified = &LuaVersion::from(&config)?;
10
11 let progress = MultiProgress::new(&config);
12
13 let bar = progress.map(|progress| {
14 progress.add(ProgressBar::from(format!(
15 "🌔 Installing Lua ({version_stringified})",
16 )))
17 });
18
19 let lua = LuaInstallation::install(version_stringified, &config, &bar).await?;
22 let lua_root = lua
23 .includes()
24 .first()
25 .and_then(|dir| dir.parent())
26 .ok_or_eyre("error getting lua include parent directory")?;
27
28 bar.map(|bar| {
29 bar.finish_with_message(format!(
30 "🌔 Installed Lua ({}) to {}",
31 version_stringified,
32 lua_root.display()
33 ))
34 });
35
36 Ok(())
37}