Skip to content
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

Add -w for GUI programs on windows #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ Example:
./src/luaot test.lua -o testcompiled.c -e # Compile test.lua to testcompiled.c and add a main func for compiling to executables
gcc -o testexec testcompiled.c src/liblua.a -I./src -lm # Compile testcompiled to an executable that will run the lua code
```
### `-w`
`-w` also enables `-e` but furthermore adds a `WinMain` function, so you can link your lua program with the Windows subsystem and not have a console window pop up when you run it.
```bash
./src/luaot test.lua -o testcompiled.c -w # Compile test.lua to testcompiled.c and add a WinMain func for compiling to executables
gcc -o testexec.exe testcompiled.c src/liblua.a -I./src -mwindows # Compile testcompiled to an executable that will run the lua code without a console window
```
# Experiments

If you are interested in reproducing the experiments from our paper, please consult the documentation in the `experiments` and `scripts` directory. Note that you must be inside the experiments directory when you run the scripts:
Expand Down
19 changes: 18 additions & 1 deletion src/luaot.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ static int nfunctions = 0;
static TString **tmname;

int executable = 0;
int use_winmain = 0;

static
void usage()
{
Expand All @@ -49,7 +51,8 @@ void usage()
" -o name output to file 'name'\n"
" -m name generate code with `name` function as main function\n"
" -s use switches instead of gotos in generated code\n"
" -e add a main symbol for executables\n",
" -e add a main symbol for executables\n"
" -w add a WinMain symbol for consoleless executables on windows\n",
program_name);
}

Expand Down Expand Up @@ -110,6 +113,9 @@ static void doargs(int argc, char **argv)
module_name = argv[i];
} else if (0 == strcmp(arg, "-e")) {
executable = 1;
} else if (0 == strcmp(arg, "-w")) {
executable = 1;
use_winmain = 1;
} else if (0 == strcmp(arg, "-o")) {
i++;
if (i >= argc) { fatal_error("missing argument for -o"); }
Expand Down Expand Up @@ -209,6 +215,17 @@ int main(int argc, char **argv)
println("lua_close(L);");
println(" return 0;");
println("}");

if (use_winmain) {
printnl();
printnl();
println("#ifdef _WIN32");
println("#include <windows.h>");
println("int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {");
println(" return main(__argc, __argv);");
println("}");
println("#endif");
}
}

return 0;
Expand Down