MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / pmain

Function pmain

third-party/lua-5.4.6/src/lua.c:625–667  ·  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

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

Callers

nothing calls this directly

Calls 15

lua_touserdataFunction · 0.70
collectargsFunction · 0.70
print_usageFunction · 0.70
print_versionFunction · 0.70
lua_pushbooleanFunction · 0.70
lua_setfieldFunction · 0.70
luaL_openlibsFunction · 0.70
createargtableFunction · 0.70
lua_gcFunction · 0.70
handle_luainitFunction · 0.70
runargsFunction · 0.70
handle_scriptFunction · 0.70

Tested by

no test coverage detected