mirror of
https://github.com/luau-lang/luau.git
synced 2025-01-05 19:09:11 +00:00
As discussed in the issue, Luau has evolved from Lua to the point where a new default extension `.luau` would be needed. This change makes the REPL and Analyze look for `.luau` extension first and if not found, fall back to `.lua`.
This commit is contained in:
parent
6342913533
commit
1e1d1f58e9
2 changed files with 20 additions and 8 deletions
|
@ -115,7 +115,12 @@ struct CliFileResolver : Luau::FileResolver
|
||||||
{
|
{
|
||||||
if (Luau::AstExprConstantString* expr = node->as<Luau::AstExprConstantString>())
|
if (Luau::AstExprConstantString* expr = node->as<Luau::AstExprConstantString>())
|
||||||
{
|
{
|
||||||
Luau::ModuleName name = std::string(expr->value.data, expr->value.size) + ".lua";
|
Luau::ModuleName name = std::string(expr->value.data, expr->value.size) + ".luau";
|
||||||
|
if (!moduleExists(name))
|
||||||
|
{
|
||||||
|
// fall back to .lua if a module with .luau doesn't exist
|
||||||
|
name = std::string(expr->value.data, expr->value.size) + ".lua";
|
||||||
|
}
|
||||||
|
|
||||||
return {{name}};
|
return {{name}};
|
||||||
}
|
}
|
||||||
|
@ -236,8 +241,15 @@ int main(int argc, char** argv)
|
||||||
if (isDirectory(argv[i]))
|
if (isDirectory(argv[i]))
|
||||||
{
|
{
|
||||||
traverseDirectory(argv[i], [&](const std::string& name) {
|
traverseDirectory(argv[i], [&](const std::string& name) {
|
||||||
if (name.length() > 4 && name.rfind(".lua") == name.length() - 4)
|
// Look for .luau first and if absent, fall back to .lua
|
||||||
|
if (name.length() > 5 && name.rfind(".luau") == name.length() - 5)
|
||||||
|
{
|
||||||
failed += !analyzeFile(frontend, name.c_str(), format, annotate);
|
failed += !analyzeFile(frontend, name.c_str(), format, annotate);
|
||||||
|
}
|
||||||
|
else if (name.length() > 4 && name.rfind(".lua") == name.length() - 4)
|
||||||
|
{
|
||||||
|
failed += !analyzeFile(frontend, name.c_str(), format, annotate);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -256,5 +268,3 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
return (format == ReportFormat::Luacheck) ? 0 : failed;
|
return (format == ReportFormat::Luacheck) ? 0 : failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
10
CLI/Repl.cpp
10
CLI/Repl.cpp
|
@ -51,9 +51,13 @@ static int lua_require(lua_State* L)
|
||||||
return finishrequire(L);
|
return finishrequire(L);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
std::optional<std::string> source = readFile(name + ".lua");
|
std::optional<std::string> source = readFile(name + ".luau");
|
||||||
if (!source)
|
if (!source)
|
||||||
luaL_argerrorL(L, 1, ("error loading " + name).c_str());
|
{
|
||||||
|
source = readFile(name + ".lua"); // try .lua if .luau doesn't exist
|
||||||
|
if (!source)
|
||||||
|
luaL_argerrorL(L, 1, ("error loading " + name).c_str()); // if neither .luau nor .lua exist, we have an error
|
||||||
|
}
|
||||||
|
|
||||||
// module needs to run in a new thread, isolated from the rest
|
// module needs to run in a new thread, isolated from the rest
|
||||||
lua_State* GL = lua_mainthread(L);
|
lua_State* GL = lua_mainthread(L);
|
||||||
|
@ -511,5 +515,3 @@ int main(int argc, char** argv)
|
||||||
return failed;
|
return failed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue