** Traverses all arguments from 'argv', returning a mask with those ** needed before running any Glua code (or an error code if it finds ** any invalid argument). 'first' returns the first not-handled argument ** (either the script name or a bad argument in case of error). */
| 548 | ** (either the script name or a bad argument in case of error). |
| 549 | */ |
| 550 | static int collectargs(char **argv, int *first) { |
| 551 | int args = 0; |
| 552 | int i; |
| 553 | for (i = 1; argv[i] != NULL; i++) { |
| 554 | *first = i; |
| 555 | if (argv[i][0] != '-') /* not an option? */ |
| 556 | return args; /* stop handling options */ |
| 557 | switch (argv[i][1]) { /* else check option */ |
| 558 | case '-': /* '--' */ |
| 559 | if (argv[i][2] != '\0') /* extra characters after '--'? */ |
| 560 | return has_error; /* invalid option */ |
| 561 | *first = i + 1; |
| 562 | return args; |
| 563 | case '\0': /* '-' */ |
| 564 | return args; /* script "name" is '-' */ |
| 565 | case 'E': |
| 566 | if (argv[i][2] != '\0') /* extra characters after 1st? */ |
| 567 | return has_error; /* invalid option */ |
| 568 | args |= has_E; |
| 569 | break; |
| 570 | case 'i': |
| 571 | args |= has_i; /* (-i implies -v) *//* FALLTHROUGH */ |
| 572 | case 'v': |
| 573 | if (argv[i][2] != '\0') /* extra characters after 1st? */ |
| 574 | return has_error; /* invalid option */ |
| 575 | args |= has_v; |
| 576 | break; |
| 577 | case 'e': |
| 578 | args |= has_e; /* FALLTHROUGH */ |
| 579 | case 'l': /* both options need an argument */ |
| 580 | if (argv[i][2] == '\0') { /* no concatenated argument? */ |
| 581 | i++; /* try next 'argv' */ |
| 582 | if (argv[i] == NULL || argv[i][0] == '-') |
| 583 | return has_error; /* no next argument or it is another option */ |
| 584 | } |
| 585 | break; |
| 586 | case 'c': |
| 587 | // 编译成字节码 |
| 588 | args |= has_c; |
| 589 | break; |
| 590 | case 'd': |
| 591 | // 反编译 |
| 592 | args |= has_d; |
| 593 | break; |
| 594 | case 's': |
| 595 | // 反汇编 |
| 596 | args |= has_s; |
| 597 | break; |
| 598 | default: /* invalid option */ |
| 599 | return has_error; |
| 600 | } |
| 601 | } |
| 602 | *first = i; /* no script name */ |
| 603 | return args; |
| 604 | } |
| 605 | |
| 606 | static int handle_luainit(lua_State *L) { |
| 607 | const char *name = "=" LUA_INITVARVERSION; |