MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / pmain

Function pmain

3rd/lua-5.4.3/src/lua.c:600–640  ·  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

598** Reads the options and handles them all.
599*/
600static 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
643int main (int argc, char **argv) {

Callers

nothing calls this directly

Calls 14

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

Tested by

no test coverage detected