mirror of
https://github.com/lune-org/lune.git
synced 2025-04-11 22:10:53 +01:00
Use loop in applying extensions
This commit is contained in:
parent
44adf6774e
commit
9e25ab51b9
1 changed files with 34 additions and 54 deletions
|
@ -39,35 +39,25 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Try to require the path with an added "luau" extension
|
// 2. Try to require the path with an added "luau" extension
|
||||||
let (luau_abs_path, luau_rel_path) = (
|
|
||||||
append_extension(&abs_path, "luau"),
|
|
||||||
append_extension(&rel_path, "luau"),
|
|
||||||
);
|
|
||||||
match require_inner(lua, ctx, &luau_abs_path, &luau_rel_path).await {
|
|
||||||
Ok(res) => return Ok(res),
|
|
||||||
Err(LuaError::SyntaxError {
|
|
||||||
message,
|
|
||||||
incomplete_input: _,
|
|
||||||
}) => {
|
|
||||||
return Err(LuaError::runtime(message));
|
|
||||||
}
|
|
||||||
Err(_) => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 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) = (
|
for extension in ["luau", "lua"] {
|
||||||
append_extension(&abs_path, "lua"),
|
match require_inner(
|
||||||
append_extension(&rel_path, "lua"),
|
lua,
|
||||||
);
|
ctx,
|
||||||
match require_inner(lua, ctx, &lua_abs_path, &lua_rel_path).await {
|
&append_extension(&abs_path, extension),
|
||||||
Ok(res) => return Ok(res),
|
&append_extension(&rel_path, extension),
|
||||||
Err(LuaError::SyntaxError {
|
)
|
||||||
message,
|
.await
|
||||||
incomplete_input: _,
|
{
|
||||||
}) => {
|
Ok(res) => return Ok(res),
|
||||||
return Err(LuaError::runtime(message));
|
Err(LuaError::SyntaxError {
|
||||||
|
message,
|
||||||
|
incomplete_input: _,
|
||||||
|
}) => {
|
||||||
|
return Err(LuaError::runtime(message));
|
||||||
|
}
|
||||||
|
Err(_) => {}
|
||||||
}
|
}
|
||||||
Err(_) => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We didn't find any direct file paths, look
|
// We didn't find any direct file paths, look
|
||||||
|
@ -76,35 +66,25 @@ where
|
||||||
let rel_init = rel_path.join("init");
|
let rel_init = rel_path.join("init");
|
||||||
|
|
||||||
// 4. Try to require the init path with an added "luau" extension
|
// 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"),
|
|
||||||
);
|
|
||||||
match require_inner(lua, ctx, &luau_abs_init, &luau_rel_init).await {
|
|
||||||
Ok(res) => return Ok(res),
|
|
||||||
Err(LuaError::SyntaxError {
|
|
||||||
message,
|
|
||||||
incomplete_input: _,
|
|
||||||
}) => {
|
|
||||||
return Err(LuaError::runtime(message));
|
|
||||||
}
|
|
||||||
Err(_) => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. Try to require the init path with an added "lua" extension
|
// 5. Try to require the init path with an added "lua" extension
|
||||||
let (lua_abs_init, lua_rel_init) = (
|
for extension in ["luau", "lua"] {
|
||||||
append_extension(&abs_init, "lua"),
|
match require_inner(
|
||||||
append_extension(&rel_init, "lua"),
|
lua,
|
||||||
);
|
ctx,
|
||||||
match require_inner(lua, ctx, &lua_abs_init, &lua_rel_init).await {
|
&append_extension(&abs_init, extension),
|
||||||
Ok(res) => return Ok(res),
|
&append_extension(&rel_init, extension),
|
||||||
Err(LuaError::SyntaxError {
|
)
|
||||||
message,
|
.await
|
||||||
incomplete_input: _,
|
{
|
||||||
}) => {
|
Ok(res) => return Ok(res),
|
||||||
return Err(LuaError::runtime(message));
|
Err(LuaError::SyntaxError {
|
||||||
|
message,
|
||||||
|
incomplete_input: _,
|
||||||
|
}) => {
|
||||||
|
return Err(LuaError::runtime(message));
|
||||||
|
}
|
||||||
|
Err(_) => {}
|
||||||
}
|
}
|
||||||
Err(_) => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nothing left to try, throw an error
|
// Nothing left to try, throw an error
|
||||||
|
|
Loading…
Add table
Reference in a new issue