** Main body of stand-alone interpreter (to be called in protected mode). ** Reads the options and handles them all. */
| 598 | ** Reads the options and handles them all. |
| 599 | */ |
| 600 | static int pmain (lua_State *L) { |
| 601 | int argc = (int)lua_tointeger(L, 1); |
| 602 | char **argv = (char **)lua_touserdata(L, 2); |
| 603 | int script; |
| 604 | int args = collectargs(argv, &script); |
| 605 | luaL_checkversion(L); /* check that interpreter has correct version */ |
| 606 | if (argv[0] && argv[0][0]) progname = argv[0]; |
| 607 | if (args == has_error) { /* bad arg? */ |
| 608 | print_usage(argv[script]); /* 'script' has index of bad arg. */ |
| 609 | return 0; |
| 610 | } |
| 611 | if (args & has_v) /* option '-v'? */ |
| 612 | print_version(); |
| 613 | if (args & has_E) { /* option '-E'? */ |
| 614 | lua_pushboolean(L, 1); /* signal for libraries to ignore env. vars. */ |
| 615 | lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV"); |
| 616 | } |
| 617 | luaL_openlibs(L); /* open standard libraries */ |
| 618 | createargtable(L, argv, argc, script); /* create table 'arg' */ |
| 619 | lua_gc(L, LUA_GCGEN, 0, 0); /* GC in generational mode */ |
| 620 | if (!(args & has_E)) { /* no option '-E'? */ |
| 621 | if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */ |
| 622 | return 0; /* error running LUA_INIT */ |
| 623 | } |
| 624 | if (!runargs(L, argv, script)) /* execute arguments -e and -l */ |
| 625 | return 0; /* something failed */ |
| 626 | if (script < argc && /* execute main script (if there is one) */ |
| 627 | handle_script(L, argv + script) != LUA_OK) |
| 628 | return 0; |
| 629 | if (args & has_i) /* -i option? */ |
| 630 | doREPL(L); /* do read-eval-print loop */ |
| 631 | else if (script == argc && !(args & (has_e | has_v))) { /* no arguments? */ |
| 632 | if (lua_stdin_is_tty()) { /* running in interactive mode? */ |
| 633 | print_version(); |
| 634 | doREPL(L); /* do read-eval-print loop */ |
| 635 | } |
| 636 | else dofile(L, NULL); /* executes stdin as a file */ |
| 637 | } |
| 638 | lua_pushboolean(L, 1); /* signal no errors */ |
| 639 | return 1; |
| 640 | } |
| 641 | |
| 642 | |
| 643 | int main (int argc, char **argv) { |
nothing calls this directly
no test coverage detected