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

Function pmain

extlibs/lua/src/lua.c:575–615  ·  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

573** Reads the options and handles them all.
574*/
575static int pmain (lua_State *L) {
576 int argc = (int)lua_tointeger(L, 1);
577 char **argv = (char **)lua_touserdata(L, 2);
578 int script;
579 int args = collectargs(argv, &script);
580 luaL_checkversion(L); /* check that interpreter has correct version */
581 if (argv[0] && argv[0][0]) progname = argv[0];
582 if (args == has_error) { /* bad arg? */
583 print_usage(argv[script]); /* 'script' has index of bad arg. */
584 return 0;
585 }
586 if (args & has_v) /* option '-v'? */
587 print_version();
588 if (args & has_E) { /* option '-E'? */
589 lua_pushboolean(L, 1); /* signal for libraries to ignore env. vars. */
590 lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
591 }
592 luaL_openlibs(L); /* open standard libraries */
593 createargtable(L, argv, argc, script); /* create table 'arg' */
594 lua_gc(L, LUA_GCGEN, 0, 0); /* GC in generational mode */
595 if (!(args & has_E)) { /* no option '-E'? */
596 if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */
597 return 0; /* error running LUA_INIT */
598 }
599 if (!runargs(L, argv, script)) /* execute arguments -e and -l */
600 return 0; /* something failed */
601 if (script < argc && /* execute main script (if there is one) */
602 handle_script(L, argv + script) != LUA_OK)
603 return 0;
604 if (args & has_i) /* -i option? */
605 doREPL(L); /* do read-eval-print loop */
606 else if (script == argc && !(args & (has_e | has_v))) { /* no arguments? */
607 if (lua_stdin_is_tty()) { /* running in interactive mode? */
608 print_version();
609 doREPL(L); /* do read-eval-print loop */
610 }
611 else dofile(L, NULL); /* executes stdin as a file */
612 }
613 lua_pushboolean(L, 1); /* signal no errors */
614 return 1;
615}
616
617
618int main (int argc, char **argv) {

Callers

nothing calls this directly

Calls 15

lua_touserdataFunction · 0.85
collectargsFunction · 0.85
luaL_checkversionFunction · 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

Tested by

no test coverage detected