1use std::fmt;
2use std::fmt::Display;
3use std::path::PathBuf;
4
5use super::version::Version;
6use crate::config::Config;
7
8#[derive(Clone)]
9pub enum Binary {
10 Lua { version: Version },
12 Custom(String),
14}
15
16impl Display for Binary {
17 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18 match self {
19 Binary::Lua { version } => write!(f, "lua {version}"),
20 Binary::Custom(cmd) => write!(f, "{cmd}"),
21 }
22 }
23}
24
25impl Binary {
26 pub fn new(version: Version, config: &Config) -> Self {
29 let variable = if version.is_luau() { "LUAU" } else { "LUA" };
30 match config.variables().get(variable).cloned() {
31 Some(bin) => Self::Custom(bin),
32 None => Self::Lua { version },
33 }
34 }
35}
36
37impl From<PathBuf> for Binary {
38 fn from(value: PathBuf) -> Self {
39 Self::Custom(value.to_string_lossy().to_string())
40 }
41}