MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / pmain

Function pmain

xrepo/packages/l/lua/port/lua/src/lua.c:607–647  ·  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

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

Callers

nothing calls this directly

Calls 14

collectargsFunction · 0.85
print_usageFunction · 0.85
print_versionFunction · 0.85
createargtableFunction · 0.85
handle_luainitFunction · 0.85
runargsFunction · 0.85
handle_scriptFunction · 0.85
doREPLFunction · 0.85
dofileFunction · 0.85
lua_touserdataFunction · 0.70
lua_pushbooleanFunction · 0.70
lua_setfieldFunction · 0.70

Tested by

no test coverage detected