** Main body of stand-alone interpreter (to be called in protected mode). ** Reads the options and handles them all. */
| 552 | ** Reads the options and handles them all. |
| 553 | */ |
| 554 | static int pmain (lua_State *L) { |
| 555 | int argc = (int)lua_tointeger(L, 1); |
| 556 | char **argv = (char **)lua_touserdata(L, 2); |
| 557 | int script; |
| 558 | int args = collectargs(argv, &script); |
| 559 | luaL_checkversion(L); /* check that interpreter has correct version */ |
| 560 | if (argv[0] && argv[0][0]) progname = argv[0]; |
| 561 | if (args == has_error) { /* bad arg? */ |
| 562 | print_usage(argv[script]); /* 'script' has index of bad arg. */ |
| 563 | return 0; |
| 564 | } |
| 565 | if (args & has_v) /* option '-v'? */ |
| 566 | print_version(); |
| 567 | if (args & has_E) { /* option '-E'? */ |
| 568 | lua_pushboolean(L, 1); /* signal for libraries to ignore env. vars. */ |
| 569 | lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV"); |
| 570 | } |
| 571 | luaL_openlibs(L); /* open standard libraries */ |
| 572 | createargtable(L, argv, argc, script); /* create table 'arg' */ |
| 573 | if (!(args & has_E)) { /* no option '-E'? */ |
| 574 | if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */ |
| 575 | return 0; /* error running LUA_INIT */ |
| 576 | } |
| 577 | if (!runargs(L, argv, script)) /* execute arguments -e and -l */ |
| 578 | return 0; /* something failed */ |
| 579 | if (script < argc && /* execute main script (if there is one) */ |
| 580 | handle_script(L, argv + script) != LUA_OK) |
| 581 | return 0; |
| 582 | if (args & has_i) /* -i option? */ |
| 583 | doREPL(L); /* do read-eval-print loop */ |
| 584 | else if (script == argc && !(args & (has_e | has_v))) { /* no arguments? */ |
| 585 | if (lua_stdin_is_tty()) { /* running in interactive mode? */ |
| 586 | print_version(); |
| 587 | doREPL(L); /* do read-eval-print loop */ |
| 588 | } |
| 589 | else dofile(L, NULL); /* executes stdin as a file */ |
| 590 | } |
| 591 | lua_pushboolean(L, 1); /* signal no errors */ |
| 592 | return 1; |
| 593 | } |
| 594 | |
| 595 | |
| 596 | int main (int argc, char **argv) { |
nothing calls this directly
no test coverage detected