MCPcopy Create free account
hub / github.com/DFHack/dfhack / pmain

Function pmain

depends/lua/src/lua.c:554–593  ·  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

552** Reads the options and handles them all.
553*/
554static int pmain (lua_State *L) {
555 int argc = (int)lua_tointeger(L, 1);
556 char **argv = (char **)lua_touserdata(L, 2);
557 int script;
558 int args = collectargs(argv, &script);
559 luaL_checkversion(L); /* check that interpreter has correct version */
560 if (argv[0] && argv[0][0]) progname = argv[0];
561 if (args == has_error) { /* bad arg? */
562 print_usage(argv[script]); /* 'script' has index of bad arg. */
563 return 0;
564 }
565 if (args & has_v) /* option '-v'? */
566 print_version();
567 if (args & has_E) { /* option '-E'? */
568 lua_pushboolean(L, 1); /* signal for libraries to ignore env. vars. */
569 lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
570 }
571 luaL_openlibs(L); /* open standard libraries */
572 createargtable(L, argv, argc, script); /* create table 'arg' */
573 if (!(args & has_E)) { /* no option '-E'? */
574 if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */
575 return 0; /* error running LUA_INIT */
576 }
577 if (!runargs(L, argv, script)) /* execute arguments -e and -l */
578 return 0; /* something failed */
579 if (script < argc && /* execute main script (if there is one) */
580 handle_script(L, argv + script) != LUA_OK)
581 return 0;
582 if (args & has_i) /* -i option? */
583 doREPL(L); /* do read-eval-print loop */
584 else if (script == argc && !(args & (has_e | has_v))) { /* no arguments? */
585 if (lua_stdin_is_tty()) { /* running in interactive mode? */
586 print_version();
587 doREPL(L); /* do read-eval-print loop */
588 }
589 else dofile(L, NULL); /* executes stdin as a file */
590 }
591 lua_pushboolean(L, 1); /* signal no errors */
592 return 1;
593}
594
595
596int main (int argc, char **argv) {

Callers

nothing calls this directly

Calls 13

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
handle_luainitFunction · 0.85
runargsFunction · 0.85
handle_scriptFunction · 0.85
doREPLFunction · 0.85

Tested by

no test coverage detected