Skip to content

Commit

Permalink
lua: add '-' command line option
Browse files Browse the repository at this point in the history
`tarantool -` now executes stdin instead of trying open "./-" script.

A part of tarantool#1265
  • Loading branch information
rtsisyk committed Aug 22, 2017
1 parent 9e45b41 commit 9db64ae
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/lua/init.c
Expand Up @@ -545,12 +545,12 @@ run_script_f(va_list ap)
*/
fiber_sleep(0.0);

if (path && access(path, F_OK) == 0) {
if (path && strcmp(path, "-") != 0 && access(path, F_OK) == 0) {
/* Execute script. */
if (luaL_loadfile(L, path) != 0)
panic("%s", lua_tostring(L, -1));
lua_main(L, argc, argv);
} else if (!isatty(STDIN_FILENO)) {
} else if (!isatty(STDIN_FILENO) || (path && strcmp(path, "-") == 0)) {
/* Execute stdin */
if (luaL_loadfile(L, NULL) != 0)
panic("%s", lua_tostring(L, -1));
Expand Down
8 changes: 4 additions & 4 deletions src/main.cc
Expand Up @@ -481,8 +481,6 @@ tarantool_free(void)
#ifdef ENABLE_GCOV
__gcov_flush();
#endif
if (script)
free(script);
/* tarantool_lua_free() was formerly reponsible for terminal reset,
* but it is no longer called
*/
Expand Down Expand Up @@ -535,6 +533,8 @@ print_help(const char *program)
puts(" -e EXPR\t\t\texecute string 'EXPR'");
puts(" -l NAME\t\t\trequire library 'NAME'");
puts(" -i\t\t\t\tenter interactive mode after executing 'SCRIPT'");
puts(" --\t\t\t\tstop handling options");
puts(" -\t\t\t\texecute stdin and stop handling options");
puts("");
puts("Please visit project home page at http://tarantool.org");
puts("to see online documentation, submit bugs or contribute a patch.");
Expand Down Expand Up @@ -604,7 +604,7 @@ main(int argc, char **argv)
for (int i = 1; i < argc; i++)
argv[i] = argv[optind + i - 1];

if (argc > 1 && access(argv[1], R_OK) != 0) {
if (argc > 1 && strcmp(argv[1], "-") && access(argv[1], R_OK) != 0) {
/*
* Somebody made a mistake in the file
* name. Be nice: open the file to set
Expand Down Expand Up @@ -636,7 +636,7 @@ main(int argc, char **argv)
if (argc > 1) {
argv++;
argc--;
script = abspath(argv[0]);
script = argv[0];
title_set_script_name(argv[0]);
}

Expand Down
4 changes: 4 additions & 0 deletions test/box-py/args.result
Expand Up @@ -10,6 +10,8 @@ When no script name is provided, the server responds to:
-e EXPR execute string 'EXPR'
-l NAME require library 'NAME'
-i enter interactive mode after executing 'SCRIPT'
-- stop handling options
- execute stdin and stop handling options

Please visit project home page at http://tarantool.org
to see online documentation, submit bugs or contribute a patch.
Expand All @@ -26,6 +28,8 @@ When no script name is provided, the server responds to:
-e EXPR execute string 'EXPR'
-l NAME require library 'NAME'
-i enter interactive mode after executing 'SCRIPT'
-- stop handling options
- execute stdin and stop handling options

Please visit project home page at http://tarantool.org
to see online documentation, submit bugs or contribute a patch.
Expand Down

0 comments on commit 9db64ae

Please sign in to comment.