Skip to content

Commit

Permalink
Remove file extension check for the main file
Browse files Browse the repository at this point in the history
  • Loading branch information
hahnavi committed Dec 17, 2024
1 parent db66574 commit e9ea73f
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,17 +379,6 @@ fn run_main_file(lua: &Lua, main_file: &String) -> anyhow::Result<()> {
.unwrap()
.to_string();

let main_file_ext = main_file_path
.extension()
.unwrap_or_default()
.to_str()
.unwrap()
.to_string();

if main_file_ext != "lua" {
return Err(anyhow::anyhow!("Main file must be a lua file."));
}

let project_dir = match main_file_path.parent() {
Some(parent) => Some(
parent
Expand All @@ -406,7 +395,7 @@ fn run_main_file(lua: &Lua, main_file: &String) -> anyhow::Result<()> {
lua.load(
chunk! {
local project_dir = $project_dir_lua
package.path = project_dir .. "/?.lua;" .. project_dir .. "/lua_modules/share/lua/5.1/?.lua;" .. project_dir .. "/lua_modules/share/lua/5.1/?/init.lua;"
package.path = project_dir .. "/?.lua;" .. project_dir .. "/?;" .. project_dir .. "/lua_modules/share/lua/5.1/?.lua;" .. project_dir .. "/lua_modules/share/lua/5.1/?/init.lua;"
package.cpath = project_dir .. "/?.so;" .. project_dir .. "/lua_modules/lib/lua/5.1/?.so;"
}
).exec()?;
Expand Down Expand Up @@ -522,14 +511,5 @@ mod tests {
let main_file = "examples/hosts.lua".to_string();
let result = run_main_file(&lua, &main_file);
assert!(result.is_ok());

// Test with a non-Lua file
let main_file = "README.md".to_string();
let result = run_main_file(&lua, &main_file);
assert!(result.is_err());
assert_eq!(
result.unwrap_err().to_string(),
"Main file must be a lua file."
);
}
}

0 comments on commit e9ea73f

Please sign in to comment.