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
43
CLI/Repl.cpp
43
CLI/Repl.cpp
|
@ -13,6 +13,11 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
enum class CompileFormat
|
||||
{
|
||||
Default,
|
||||
|
@ -399,7 +404,12 @@ static bool compileFile(const char* name, CompileFormat format)
|
|||
printf("%s", bcb.dumpEverything().c_str());
|
||||
break;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -458,33 +468,16 @@ int main(int argc, char** argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if ((argc >= 2 && strcmp(argv[1], "--compile=text") == 0) || strcmp(argv[1], "--compile") == 0)
|
||||
|
||||
if (argc >= 2 && strncmp(argv[1], "--compile", strlen("--compile")) == 0)
|
||||
{
|
||||
int failed = 0;
|
||||
CompileFormat format = CompileFormat::Default;
|
||||
|
||||
for (int i = 2; i < argc; ++i)
|
||||
if (strcmp(argv[1], "--compile=binary") == 0)
|
||||
{
|
||||
if (argv[i][0] == '-')
|
||||
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);
|
||||
}
|
||||
format = CompileFormat::Binary;
|
||||
}
|
||||
|
||||
return failed;
|
||||
}
|
||||
|
||||
if (argc >= 2 && strcmp(argv[1], "--compile=binary") == 0)
|
||||
{
|
||||
int failed = 0;
|
||||
|
||||
for (int i = 2; i < argc; ++i)
|
||||
|
@ -496,12 +489,12 @@ int main(int argc, char** argv)
|
|||
{
|
||||
traverseDirectory(argv[i], [&](const std::string& name) {
|
||||
if (name.length() > 4 && name.rfind(".lua") == name.length() - 4)
|
||||
failed += !compileFile(name.c_str(), CompileFormat::Binary);
|
||||
failed += !compileFile(name.c_str(), format);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
failed += !compileFile(argv[i], CompileFormat::Binary);
|
||||
failed += !compileFile(argv[i], format);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue