mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Update Repl.cpp
This commit is contained in:
parent
ab48847e34
commit
b69f38e6d1
1 changed files with 19 additions and 26 deletions
45
CLI/Repl.cpp
45
CLI/Repl.cpp
|
@ -13,6 +13,11 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <io.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
enum class CompileFormat
|
enum class CompileFormat
|
||||||
{
|
{
|
||||||
Default,
|
Default,
|
||||||
|
@ -399,7 +404,12 @@ static bool compileFile(const char* name, CompileFormat format)
|
||||||
printf("%s", bcb.dumpEverything().c_str());
|
printf("%s", bcb.dumpEverything().c_str());
|
||||||
break;
|
break;
|
||||||
case CompileFormat::Binary:
|
case CompileFormat::Binary:
|
||||||
printf("%s", bcb.getBytecode().data());
|
#ifdef _WIN32
|
||||||
|
_setmode(_fileno(stdout), _O_BINARY);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::string Bytecode = bcb.getBytecode();
|
||||||
|
fwrite(Bytecode.c_str(), 1, Bytecode.size(), stdout);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,33 +468,16 @@ int main(int argc, char** argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((argc >= 2 && strcmp(argv[1], "--compile=text") == 0) || strcmp(argv[1], "--compile") == 0)
|
|
||||||
{
|
|
||||||
int failed = 0;
|
|
||||||
|
|
||||||
for (int i = 2; i < argc; ++i)
|
if (argc >= 2 && strncmp(argv[1], "--compile", strlen("--compile")) == 0)
|
||||||
|
{
|
||||||
|
CompileFormat format = CompileFormat::Default;
|
||||||
|
|
||||||
|
if (strcmp(argv[1], "--compile=binary") == 0)
|
||||||
{
|
{
|
||||||
if (argv[i][0] == '-')
|
format = CompileFormat::Binary;
|
||||||
continue;
|
|
||||||
|
|
||||||
if (isDirectory(argv[i]))
|
|
||||||
{
|
|
||||||
traverseDirectory(argv[i], [&](const std::string& name) {
|
|
||||||
if (name.length() > 4 && name.rfind(".lua") == name.length() - 4)
|
|
||||||
failed += !compileFile(name.c_str(), CompileFormat::Default);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
failed += !compileFile(argv[i], CompileFormat::Default);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc >= 2 && strcmp(argv[1], "--compile=binary") == 0)
|
|
||||||
{
|
|
||||||
int failed = 0;
|
int failed = 0;
|
||||||
|
|
||||||
for (int i = 2; i < argc; ++i)
|
for (int i = 2; i < argc; ++i)
|
||||||
|
@ -496,12 +489,12 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
traverseDirectory(argv[i], [&](const std::string& name) {
|
traverseDirectory(argv[i], [&](const std::string& name) {
|
||||||
if (name.length() > 4 && name.rfind(".lua") == name.length() - 4)
|
if (name.length() > 4 && name.rfind(".lua") == name.length() - 4)
|
||||||
failed += !compileFile(name.c_str(), CompileFormat::Binary);
|
failed += !compileFile(name.c_str(), format);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
failed += !compileFile(argv[i], CompileFormat::Binary);
|
failed += !compileFile(argv[i], format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue