-
Notifications
You must be signed in to change notification settings - Fork 393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save bytecode to file through CLI #170
Conversation
Thanks for the PR! A few notes:
|
I have fixed these issues. You can now use |
Please don't close this PR. It's not necessary - you can update it without closing - and that results in needless notifications for people watching the repository. |
Sorry about that 👍 |
CLI/Repl.cpp
Outdated
printf("%s", bcb.dumpEverything().c_str()); | ||
break; | ||
case CompileFormat::Binary: | ||
printf("%s", bcb.getBytecode().data()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use fwrite
to stdout
since the data is binary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Left a few comments.
CLI/Repl.cpp
Outdated
@@ -444,7 +458,32 @@ int main(int argc, char** argv) | |||
return 0; | |||
} | |||
|
|||
if (argc >= 2 && strcmp(argv[1], "--compile") == 0) | |||
if ((argc >= 2 && strcmp(argv[1], "--compile=text") == 0) || strcmp(argv[1], "--compile") == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be simpler if we just have if (argc >= 2 && strncmp(argv[1], "--compile", strlen("--compile")) == 0)
, and inside the if
we can compare the argv to determine the format. That way you get to reuse the rest of the code between two branches.
CLI/Repl.cpp
Outdated
@@ -444,7 +458,32 @@ int main(int argc, char** argv) | |||
return 0; | |||
} | |||
|
|||
if (argc >= 2 && strcmp(argv[1], "--compile") == 0) | |||
if ((argc >= 2 && strcmp(argv[1], "--compile=text") == 0) || strcmp(argv[1], "--compile") == 0) | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs something like _setmode(_fileno(stdout), O_BINARY);
when _WIN32 is defined, see
https://stackoverflow.com/questions/23107609/is-there-way-to-set-stdout-to-binary-mode
CLI/Repl.cpp
Outdated
if (isDirectory(argv[i])) | ||
{ | ||
traverseDirectory(argv[i], [&](const std::string& name) { | ||
if (name.length() > 4 && name.rfind(".lua") == name.length() - 4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
luau
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'll take care of .luau support in a separate change.
This pull request adds support to save script bytecode through the CLI using the
--binary
option. This feature is very useful for developers who would like to parse luau bytecode using 3rd-party programs, as said in this feature request #151