diff --git a/src/lune/globals/require/path.rs b/src/lune/globals/require/path.rs index 92546e3..0e443fd 100644 --- a/src/lune/globals/require/path.rs +++ b/src/lune/globals/require/path.rs @@ -28,7 +28,7 @@ where return Ok(res); } - // 2. Try to require the path with an added "lua" extension + // 3. Try to require the path with an added "lua" extension let (lua_abs_path, lua_rel_path) = ( append_extension(&abs_path, "lua"), append_extension(&rel_path, "lua"), @@ -37,6 +37,29 @@ where return Ok(res); } + // We didn't find any direct file paths, look + // for directories with "init" files in them... + let abs_init = abs_path.join("init"); + let rel_init = rel_path.join("init"); + + // 4. Try to require the init path with an added "luau" extension + let (luau_abs_init, luau_rel_init) = ( + append_extension(&abs_init, "luau"), + append_extension(&rel_init, "luau"), + ); + if let Ok(res) = require_inner(ctx, &luau_abs_init, &luau_rel_init).await { + return Ok(res); + } + + // 5. Try to require the init path with an added "lua" extension + let (lua_abs_init, lua_rel_init) = ( + append_extension(&abs_init, "lua"), + append_extension(&rel_init, "lua"), + ); + if let Ok(res) = require_inner(ctx, &lua_abs_init, &lua_rel_init).await { + return Ok(res); + } + // Nothing left to try, throw an error Err(LuaError::runtime(format!( "No file exist at the path '{}'",