MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / pmain

Function pmain

src/Chain/libraries/glua/single_glua_src/main.cpp:624–685  ·  view source on GitHub ↗

** Main body of stand-alone interpreter (to be called in protected mode). ** Reads the options and handles them all. */

Source from the content-addressed store, hash-verified

622** Reads the options and handles them all.
623*/
624static int pmain(lua_State *L) {
625 int argc = (int)lua_tointeger(L, 1);
626 char **argv = (char **)lua_touserdata(L, 2);
627 int script;
628 int args = collectargs(argv, &script);
629 luaL_checkversion(L); /* check that interpreter has correct version */
630 if (argv[0] && argv[0][0]) progname = argv[0];
631 if (args == has_error) { /* bad arg? */
632 print_usage(argv[script]); /* 'script' has index of bad arg. */
633 return 0;
634 }
635 if (args & has_v) /* option '-v'? */
636 print_version();
637 if (args & has_E) { /* option '-E'? */
638 lua_pushboolean(L, 1); /* signal for libraries to ignore env. vars. */
639 lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
640 }
641 luaL_openlibs(L); /* open standard libraries */
642 createargtable(L, argv, argc, script); /* create table 'arg' */
643 if (!(args & has_E)) { /* no option '-E'? */
644 if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */
645 return 0; /* error running LUA_INIT */
646 }
647 if (args & has_d)
648 {
649 // decompile
650 run_decompile_script(L, argv, script);
651 return 0;
652 }
653 if (args & has_s)
654 {
655 // disassemble
656 run_disassemble_script(L, argv, script);
657 return 0;
658 }
659 if (args & has_c)
660 {
661 // compile
662 run_compile_script(L, argv, script);
663 return 0;
664 }
665 //if (!runargs(L, argv, script)) /* execute arguments -e and -l */
666 // return 0; /* something failed */
667 if (script < argc &&
668 handle_script(L, argv + script) != LUA_OK) /* execute main script (if there is one) */
669 return 0;
670 if (args & has_i) /* -i option? */
671 doREPL(L); /* do read-eval-print loop */
672 else if (script == argc && !(args & (has_e | has_v))) { /* no arguments? */
673 /*
674 if (lua_stdin_is_tty()) { // running in interactive mode?
675 print_version();
676 doREPL(L); // do read-eval-print loop
677 }
678 */
679 // else
680 // dofile(L, NULL); /* executes stdin as a file */
681 printf("need filename arg");

Callers

nothing calls this directly

Calls 15

lua_touserdataFunction · 0.85
lua_pushbooleanFunction · 0.85
lua_setfieldFunction · 0.85
luaL_openlibsFunction · 0.85
run_decompile_scriptFunction · 0.85
run_disassemble_scriptFunction · 0.85
run_compile_scriptFunction · 0.85
printfClass · 0.85
collectargsFunction · 0.70
print_usageFunction · 0.70
print_versionFunction · 0.70
createargtableFunction · 0.70

Tested by

no test coverage detected